
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../../" src="../../../../../_static/documentation_options.js"></script>
    <script src="../../../../../_static/jquery.js"></script>
    <script src="../../../../../_static/underscore.js"></script>
    <script src="../../../../../_static/doctools.js"></script>
    <script src="../../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module contains the main object used to identify the coordination environments in a given structure.</span>
<span class="sd">If you use this module, please cite the following:</span>

<span class="sd">David Waroquiers, Xavier Gonze, Gian-Marco Rignanese, Cathrin Welker-Nieuwoudt, Frank Rosowski,</span>
<span class="sd">Michael Goebel, Stephan Schenk, Peter Degelmann, Rute Andre, Robert Glaum, and Geoffroy Hautier,</span>
<span class="sd">&quot;Statistical analysis of coordination environments in oxides&quot;,</span>
<span class="sd">Chem. Mater., 2017, 29 (19), pp 8346–8360,</span>
<span class="sd">DOI: 10.1021/acs.chemmater.7b02766</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;David Waroquiers&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2012, The Materials Project&quot;</span>
<span class="n">__credits__</span> <span class="o">=</span> <span class="s2">&quot;Geoffroy Hautier&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;2.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;David Waroquiers&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;david.waroquiers@gmail.com&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Feb 20, 2016&quot;</span>

<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span>
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">shuffle</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">numpy.linalg</span> <span class="kn">import</span> <span class="n">norm</span>
<span class="kn">from</span> <span class="nn">numpy.linalg</span> <span class="kn">import</span> <span class="n">svd</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.bond_valence</span> <span class="kn">import</span> <span class="n">BVAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.chemenv_strategies</span> <span class="kn">import</span> \
    <span class="n">MultiWeightsChemenvStrategy</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.coordination_geometries</span> <span class="kn">import</span> \
    <span class="n">AllCoordinationGeometries</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.coordination_geometries</span> <span class="kn">import</span> \
    <span class="n">EXPLICIT_PERMUTATIONS</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.coordination_geometries</span> <span class="kn">import</span> \
    <span class="n">SEPARATION_PLANE</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.structure_environments</span> <span class="kn">import</span> \
    <span class="n">ChemicalEnvironments</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.structure_environments</span> <span class="kn">import</span> \
    <span class="n">LightStructureEnvironments</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.structure_environments</span> <span class="kn">import</span> \
    <span class="n">StructureEnvironments</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.coordination_environments.voronoi</span> <span class="kn">import</span> \
    <span class="n">DetailedVoronoiContainer</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.utils.coordination_geometry_utils</span> <span class="kn">import</span> <span class="n">Plane</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.utils.coordination_geometry_utils</span> <span class="kn">import</span> \
    <span class="n">collinear</span><span class="p">,</span> <span class="n">separation_in_list</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.utils.coordination_geometry_utils</span> <span class="kn">import</span> \
    <span class="n">sort_separation</span><span class="p">,</span> <span class="n">sort_separation_tuple</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.utils.defs_utils</span> <span class="kn">import</span> <span class="n">chemenv_citations</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.lattice</span> <span class="kn">import</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Specie</span>

<span class="n">debug</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">DIST_TOLERANCES</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.02</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]</span>


<div class="viewcode-block" id="AbstractGeometry"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry">[docs]</a><span class="k">class</span> <span class="nc">AbstractGeometry</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class used to describe a geometry (perfect or distorted)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">central_site</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">bare_coords</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">centering_type</span><span class="o">=</span><span class="s1">&#39;standard&#39;</span><span class="p">,</span>
                 <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for the abstract geometry</span>
<span class="sd">        :param central_site: Coordinates of the central site</span>
<span class="sd">        :param bare_coords: Coordinates of the neighbors of the central site</span>
<span class="sd">        :param centering_type: How to center the abstract geometry</span>
<span class="sd">        :param include_central_site_in_centroid: When the centering is on the centroid, the central site is included</span>
<span class="sd">            if this parameter is set to True.</span>
<span class="sd">        :raise: ValueError if the parameters are not consistent</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">bcoords</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bare_coords</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bare_centre</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">central_site</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_without_centre</span> <span class="o">=</span> <span class="n">bcoords</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_with_centre</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">central_site</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_with_centre</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(([</span><span class="bp">self</span><span class="o">.</span><span class="n">bare_points_with_centre</span><span class="p">],</span> <span class="n">bcoords</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">centroid_without_centre</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bare_points_without_centre</span><span class="p">,</span>
                                               <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">centroid_with_centre</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bare_points_with_centre</span><span class="p">,</span>
                                            <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_csc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_with_centre</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_csc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_without_centre</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_ctwcc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_with_centre</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">centroid_with_centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwcc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_without_centre</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">centroid_with_centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_ctwocc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_with_centre</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">centroid_without_centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwocc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_without_centre</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">centroid_without_centre</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span> <span class="o">=</span> <span class="n">centering_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span> <span class="o">=</span> <span class="n">include_central_site_in_centroid</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bare_central_site</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">central_site</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">centering_type</span> <span class="o">==</span> <span class="s1">&#39;standard&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bare_coords</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">include_central_site_in_centroid</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;The center is the central site, no calculation of the centroid, &quot;</span>
                        <span class="s2">&quot;variable include_central_site_in_centroid should be set to False&quot;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">central_site</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;Centering_type is central_site, the central site should be given&quot;</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">centre</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">central_site</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">total</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">bcoords</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">include_central_site_in_centroid</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">central_site</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                            <span class="s2">&quot;The centroid includes the central site but no central site is given&quot;</span><span class="p">)</span>
                    <span class="n">total</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_centre</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">centre</span> <span class="o">=</span> <span class="n">total</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">bare_coords</span><span class="p">))</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">centre</span> <span class="o">=</span> <span class="n">total</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">bare_coords</span><span class="p">))</span>
        <span class="k">elif</span> <span class="n">centering_type</span> <span class="o">==</span> <span class="s1">&#39;central_site&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">include_central_site_in_centroid</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s2">&quot;The center is the central site, no calculation of the centroid, &quot;</span>
                    <span class="s2">&quot;variable include_central_site_in_centroid should be set to False&quot;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">central_site</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s2">&quot;Centering_type is central_site, the central site should be given&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">centre</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">central_site</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">centering_type</span> <span class="o">==</span> <span class="s1">&#39;centroid&#39;</span><span class="p">:</span>
            <span class="n">total</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">bcoords</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">include_central_site_in_centroid</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">central_site</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;The centroid includes the central site but no central site is given&quot;</span><span class="p">)</span>
                <span class="n">total</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_centre</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">centre</span> <span class="o">=</span> <span class="n">total</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">bare_coords</span><span class="p">))</span> <span class="o">+</span> <span class="mf">1.0</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">centre</span> <span class="o">=</span> <span class="n">total</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">bare_coords</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bare_coords</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_points_without_centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_coords</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bare_coords</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">central_site</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bare_central_site</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">centre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">coords</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_coords</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bare_coords</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bare_coords</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        String representation of the AbstractGeometry</span>
<span class="sd">        :return: String representation of the AbstractGeometry</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">outs</span> <span class="o">=</span> <span class="p">[</span>
            <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">Abstract Geometry with </span><span class="si">{n}</span><span class="s1"> points :&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coords</span><span class="p">))]</span>
        <span class="k">for</span> <span class="n">pp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">coords</span><span class="p">:</span>
            <span class="n">outs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;  </span><span class="si">{pp}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">pp</span><span class="o">=</span><span class="n">pp</span><span class="p">))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span> <span class="o">==</span> <span class="s1">&#39;standard&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span><span class="p">:</span>
                <span class="n">outs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="s1">&#39;Points are referenced to the central site for coordination numbers &lt; 5&#39;</span>
                    <span class="s1">&#39; and to the centroid (calculated with the central site) for coordination&#39;</span>
                    <span class="s1">&#39; numbers &gt;= 5 : </span><span class="si">{c}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centre</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">outs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="s1">&#39;Points are referenced to the central site for coordination numbers &lt; 5&#39;</span>
                    <span class="s1">&#39; and to the centroid (calculated without the central site) for coordination&#39;</span>
                    <span class="s1">&#39; numbers &gt;= 5 : </span><span class="si">{c}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centre</span><span class="p">))</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span> <span class="o">==</span> <span class="s1">&#39;central_site&#39;</span><span class="p">:</span>
            <span class="n">outs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Points are referenced to the central site : </span><span class="si">{c}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centre</span><span class="p">))</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span> <span class="o">==</span> <span class="s1">&#39;centroid&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span><span class="p">:</span>
                <span class="n">outs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Points are referenced to the centroid &#39;</span>
                            <span class="s1">&#39;(calculated with the central site) :</span><span class="se">\n</span><span class="s1">  </span><span class="si">{c}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centre</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">outs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Points are referenced to the centroid&#39;</span>
                            <span class="s1">&#39; (calculated without the central site) :</span><span class="se">\n</span><span class="s1">  </span><span class="si">{c}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centre</span><span class="p">))</span>
        <span class="k">return</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">outs</span><span class="p">)</span>

<div class="viewcode-block" id="AbstractGeometry.from_cg"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry.from_cg">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_cg</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">cg</span><span class="p">,</span> <span class="n">centering_type</span><span class="o">=</span><span class="s1">&#39;standard&#39;</span><span class="p">,</span>
                <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param cg:</span>
<span class="sd">        :param centering_type:</span>
<span class="sd">        :param include_central_site_in_centroid:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">central_site</span> <span class="o">=</span> <span class="n">cg</span><span class="o">.</span><span class="n">get_central_site</span><span class="p">()</span>
        <span class="n">bare_coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">pt</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span> <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">cg</span><span class="o">.</span><span class="n">points</span><span class="p">]</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">central_site</span><span class="o">=</span><span class="n">central_site</span><span class="p">,</span> <span class="n">bare_coords</span><span class="o">=</span><span class="n">bare_coords</span><span class="p">,</span>
                   <span class="n">centering_type</span><span class="o">=</span><span class="n">centering_type</span><span class="p">,</span>
                   <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="n">include_central_site_in_centroid</span><span class="p">)</span></div>

<div class="viewcode-block" id="AbstractGeometry.points_wcs_csc"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry.points_wcs_csc">[docs]</a>    <span class="k">def</span> <span class="nf">points_wcs_csc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutation</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param permutation:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">permutation</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_csc</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_csc</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_csc</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">permutation</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)))</span></div>

<div class="viewcode-block" id="AbstractGeometry.points_wocs_csc"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry.points_wocs_csc">[docs]</a>    <span class="k">def</span> <span class="nf">points_wocs_csc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutation</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param permutation:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">permutation</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_csc</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_csc</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">permutation</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span></div>

<div class="viewcode-block" id="AbstractGeometry.points_wcs_ctwcc"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry.points_wcs_ctwcc">[docs]</a>    <span class="k">def</span> <span class="nf">points_wcs_ctwcc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutation</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param permutation:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">permutation</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_ctwcc</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_ctwcc</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwcc</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">permutation</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)))</span></div>

<div class="viewcode-block" id="AbstractGeometry.points_wocs_ctwcc"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry.points_wocs_ctwcc">[docs]</a>    <span class="k">def</span> <span class="nf">points_wocs_ctwcc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutation</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param permutation:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">permutation</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwcc</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwcc</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">permutation</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span></div>

<div class="viewcode-block" id="AbstractGeometry.points_wcs_ctwocc"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry.points_wcs_ctwocc">[docs]</a>    <span class="k">def</span> <span class="nf">points_wcs_ctwocc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutation</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param permutation:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">permutation</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_ctwocc</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_points_wcs_ctwocc</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwocc</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">permutation</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)))</span></div>

<div class="viewcode-block" id="AbstractGeometry.points_wocs_ctwocc"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.AbstractGeometry.points_wocs_ctwocc">[docs]</a>    <span class="k">def</span> <span class="nf">points_wocs_ctwocc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutation</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param permutation:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">permutation</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwocc</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_points_wocs_ctwocc</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">permutation</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">cn</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Coordination number</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coords</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">coordination_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Coordination number</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coords</span><span class="p">)</span></div>


<div class="viewcode-block" id="symmetry_measure"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.symmetry_measure">[docs]</a><span class="k">def</span> <span class="nf">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="p">,</span> <span class="n">points_perfect</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computes the continuous symmetry measure of the (distorted) set of points &quot;points_distorted&quot; with respect to the</span>
<span class="sd">    (perfect) set of points &quot;points_perfect&quot;.</span>
<span class="sd">    :param points_distorted: List of points describing a given (distorted) polyhedron for which the symmetry measure</span>
<span class="sd">        has to be computed with respect to the model polyhedron described by the list of points</span>
<span class="sd">        &quot;points_perfect&quot;.</span>
<span class="sd">    :param points_perfect: List of &quot;perfect&quot; points describing a given model polyhedron.</span>
<span class="sd">    :return: The continuous symmetry measure of the distorted polyhedron with respect to the perfect polyhedron</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># When there is only one point, the symmetry measure is 0.0 by definition</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">points_distorted</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="s1">&#39;scaling_factor&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;rotation_matrix&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span>
    <span class="c1"># Find the rotation matrix that aligns the distorted points to the perfect points in a least-square sense.</span>
    <span class="n">rot</span> <span class="o">=</span> <span class="n">find_rotation</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                        <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
    <span class="c1"># Find the scaling factor between the distorted points and the perfect points in a least-square sense.</span>
    <span class="n">scaling_factor</span><span class="p">,</span> <span class="n">rotated_coords</span><span class="p">,</span> <span class="n">points_perfect</span> <span class="o">=</span> <span class="n">find_scaling_factor</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                                                                         <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">,</span>
                                                                         <span class="n">rot</span><span class="o">=</span><span class="n">rot</span><span class="p">)</span>
    <span class="c1"># Compute the continuous symmetry measure [see Eq. 1 in Pinsky et al., Inorganic Chemistry 37, 5575 (1998)]</span>
    <span class="n">rotated_coords</span> <span class="o">=</span> <span class="n">scaling_factor</span> <span class="o">*</span> <span class="n">rotated_coords</span>
    <span class="n">diff</span> <span class="o">=</span> <span class="n">points_perfect</span> <span class="o">-</span> <span class="n">rotated_coords</span>
    <span class="n">num</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">tensordot</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="n">diff</span><span class="p">)</span>
    <span class="n">denom</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">tensordot</span><span class="p">(</span><span class="n">points_perfect</span><span class="p">,</span> <span class="n">points_perfect</span><span class="p">)</span>
    <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">:</span> <span class="n">num</span> <span class="o">/</span> <span class="n">denom</span> <span class="o">*</span> <span class="mf">100.0</span><span class="p">,</span> <span class="s1">&#39;scaling_factor&#39;</span><span class="p">:</span> <span class="n">scaling_factor</span><span class="p">,</span> <span class="s1">&#39;rotation_matrix&#39;</span><span class="p">:</span> <span class="n">rot</span><span class="p">}</span></div>


<div class="viewcode-block" id="find_rotation"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.find_rotation">[docs]</a><span class="k">def</span> <span class="nf">find_rotation</span><span class="p">(</span><span class="n">points_distorted</span><span class="p">,</span> <span class="n">points_perfect</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This finds the rotation matrix that aligns the (distorted) set of points &quot;points_distorted&quot; with respect to the</span>
<span class="sd">    (perfect) set of points &quot;points_perfect&quot; in a least-square sense.</span>
<span class="sd">    :param points_distorted: List of points describing a given (distorted) polyhedron for which the rotation that</span>
<span class="sd">        aligns these points in a least-square sense to the set of perfect points &quot;points_perfect&quot;</span>
<span class="sd">    :param points_perfect: List of &quot;perfect&quot; points describing a given model polyhedron.</span>
<span class="sd">    :return: The rotation matrix</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">H</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">points_perfect</span><span class="p">)</span>
    <span class="p">[</span><span class="n">U</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">Vt</span><span class="p">]</span> <span class="o">=</span> <span class="n">svd</span><span class="p">(</span><span class="n">H</span><span class="p">)</span>
    <span class="n">rot</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">Vt</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">U</span><span class="o">.</span><span class="n">T</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">rot</span></div>


<div class="viewcode-block" id="find_scaling_factor"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.find_scaling_factor">[docs]</a><span class="k">def</span> <span class="nf">find_scaling_factor</span><span class="p">(</span><span class="n">points_distorted</span><span class="p">,</span> <span class="n">points_perfect</span><span class="p">,</span> <span class="n">rot</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This finds the scaling factor between the (distorted) set of points &quot;points_distorted&quot; and the</span>
<span class="sd">    (perfect) set of points &quot;points_perfect&quot; in a least-square sense.</span>
<span class="sd">    :param points_distorted: List of points describing a given (distorted) polyhedron for which the scaling factor has</span>
<span class="sd">                             to be obtained.</span>
<span class="sd">    :param points_perfect: List of &quot;perfect&quot; points describing a given model polyhedron.</span>
<span class="sd">    :param rot: The rotation matrix</span>
<span class="sd">    :return: The scaling factor between the two structures and the rotated set of (distorted) points.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">rotated_coords</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">rot</span><span class="p">,</span> <span class="n">points_distorted</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
    <span class="n">num</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">tensordot</span><span class="p">(</span><span class="n">rotated_coords</span><span class="p">,</span> <span class="n">points_perfect</span><span class="p">)</span>
    <span class="n">denom</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">tensordot</span><span class="p">(</span><span class="n">rotated_coords</span><span class="p">,</span> <span class="n">rotated_coords</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">num</span> <span class="o">/</span> <span class="n">denom</span><span class="p">,</span> <span class="n">rotated_coords</span><span class="p">,</span> <span class="n">points_perfect</span></div>


<div class="viewcode-block" id="LocalGeometryFinder"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder">[docs]</a><span class="k">class</span> <span class="nc">LocalGeometryFinder</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Main class used to find the local environments in a structure</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">DEFAULT_BVA_DISTANCE_SCALE_FACTOR</span> <span class="o">=</span> <span class="mf">1.0</span>
    <span class="n">BVA_DISTANCE_SCALE_FACTORS</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;experimental&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span> <span class="s1">&#39;GGA_relaxed&#39;</span><span class="p">:</span> <span class="mf">1.015</span><span class="p">,</span>
                                  <span class="s1">&#39;LDA_relaxed&#39;</span><span class="p">:</span> <span class="mf">0.995</span><span class="p">}</span>
    <span class="n">DEFAULT_SPG_ANALYZER_OPTIONS</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;symprec&#39;</span><span class="p">:</span> <span class="mf">1e-3</span><span class="p">,</span> <span class="s1">&#39;angle_tolerance&#39;</span><span class="p">:</span> <span class="mi">5</span><span class="p">}</span>
    <span class="n">STRUCTURE_REFINEMENT_NONE</span> <span class="o">=</span> <span class="s1">&#39;none&#39;</span>
    <span class="n">STRUCTURE_REFINEMENT_REFINED</span> <span class="o">=</span> <span class="s1">&#39;refined&#39;</span>
    <span class="n">STRUCTURE_REFINEMENT_SYMMETRIZED</span> <span class="o">=</span> <span class="s1">&#39;symmetrized&#39;</span>

    <span class="n">DEFAULT_STRATEGY</span> <span class="o">=</span> <span class="n">MultiWeightsChemenvStrategy</span><span class="o">.</span><span class="n">stats_article_weights_parameters</span><span class="p">()</span>

    <span class="n">PRESETS</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;maximum_distance_factor&#39;</span><span class="p">:</span> <span class="mf">2.0</span><span class="p">,</span>
                           <span class="s1">&#39;minimum_angle_factor&#39;</span><span class="p">:</span> <span class="mf">0.05</span><span class="p">,</span>
                           <span class="s1">&#39;voronoi_normalized_distance_tolerance&#39;</span><span class="p">:</span> <span class="mf">0.05</span><span class="p">,</span>
                           <span class="s1">&#39;voronoi_normalized_angle_tolerance&#39;</span><span class="p">:</span> <span class="mf">0.03</span><span class="p">,</span>
                           <span class="s1">&#39;optimization&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">}}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">permutations_safe_override</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">plane_ordering_override</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">debug_level</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">plane_safe_permutations</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">only_symbols</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for the LocalGeometryFinder, initializes the list of coordination geometries</span>
<span class="sd">        :param permutations_safe_override: If set to True, all permutations are tested (very time-consuming for large</span>
<span class="sd">            coordination numbers!)</span>
<span class="sd">        :param plane_ordering_override: If set to False, the ordering of the points in the plane is disabled</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span> <span class="o">=</span> <span class="n">AllCoordinationGeometries</span><span class="p">(</span>
            <span class="n">permutations_safe_override</span><span class="o">=</span><span class="n">permutations_safe_override</span><span class="p">,</span>
            <span class="n">only_symbols</span><span class="o">=</span><span class="n">only_symbols</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">permutations_safe_override</span> <span class="o">=</span> <span class="n">permutations_safe_override</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plane_ordering_override</span> <span class="o">=</span> <span class="n">plane_ordering_override</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plane_safe_permutations</span> <span class="o">=</span> <span class="n">plane_safe_permutations</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setup_parameters</span><span class="p">(</span><span class="n">centering_type</span><span class="o">=</span><span class="s1">&#39;centroid&#39;</span><span class="p">,</span>
                              <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                              <span class="n">bva_distance_scale_factor</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                              <span class="n">structure_refinement</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">STRUCTURE_REFINEMENT_NONE</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">chemenv_citations</span><span class="p">())</span>

<div class="viewcode-block" id="LocalGeometryFinder.setup_parameters"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_parameters">[docs]</a>    <span class="k">def</span> <span class="nf">setup_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">centering_type</span><span class="o">=</span><span class="s1">&#39;standard&#39;</span><span class="p">,</span>
                         <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                         <span class="n">bva_distance_scale_factor</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                         <span class="n">structure_refinement</span><span class="o">=</span><span class="n">STRUCTURE_REFINEMENT_REFINED</span><span class="p">,</span>
                         <span class="n">spg_analyzer_options</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Setup of the parameters for the coordination geometry finder. A reference point for the geometries has to be</span>
<span class="sd">        chosen. This can be the centroid of the structure (including or excluding the atom for which the coordination</span>
<span class="sd">        geometry is looked for) or the atom itself. In the &#39;standard&#39; centering_type, the reference point is the central</span>
<span class="sd">        atom for coordination numbers 1, 2, 3 and 4 and the centroid for coordination numbers &gt; 4.</span>
<span class="sd">        :param centering_type: Type of the reference point (centering) &#39;standard&#39;, &#39;centroid&#39; or &#39;central_site&#39;</span>
<span class="sd">        :param include_central_site_in_centroid: In case centering_type is &#39;centroid&#39;, the central site is included if</span>
<span class="sd">            this value is set to True.</span>
<span class="sd">        :param bva_distance_scale_factor: Scaling factor for the bond valence analyzer (this might be different whether</span>
<span class="sd">            the structure is an experimental one, an LDA or a GGA relaxed one, or any other relaxation scheme (where</span>
<span class="sd">            under- or over-estimation of bond lengths is known).</span>
<span class="sd">        :param structure_refinement: Refinement of the structure. Can be &quot;none&quot;, &quot;refined&quot; or &quot;symmetrized&quot;.</span>
<span class="sd">        :param spg_analyzer_options: Options for the SpaceGroupAnalyzer (dictionary specifying &quot;symprec&quot;</span>
<span class="sd">            and &quot;angle_tolerance&quot;. See pymatgen&#39;s SpaceGroupAnalyzer for more information.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span> <span class="o">=</span> <span class="n">centering_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span> <span class="o">=</span> <span class="n">include_central_site_in_centroid</span>
        <span class="k">if</span> <span class="n">bva_distance_scale_factor</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bva_distance_scale_factor</span> <span class="o">=</span> <span class="n">bva_distance_scale_factor</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bva_distance_scale_factor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_BVA_DISTANCE_SCALE_FACTOR</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure_refinement</span> <span class="o">=</span> <span class="n">structure_refinement</span>
        <span class="k">if</span> <span class="n">spg_analyzer_options</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_SPG_ANALYZER_OPTIONS</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_options</span> <span class="o">=</span> <span class="n">spg_analyzer_options</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_parameter"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_parameter">[docs]</a>    <span class="k">def</span> <span class="nf">setup_parameter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parameter</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Setup of one specific parameter to the given value. The other parameters are unchanged. See setup_parameters</span>
<span class="sd">        method for the list of possible parameters</span>
<span class="sd">        :param parameter: Parameter to setup/update</span>
<span class="sd">        :param value: Value of the parameter</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">parameter</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_structure"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_structure">[docs]</a>    <span class="k">def</span> <span class="nf">setup_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets up the structure for which the coordination geometries have to be identified. The structure is analyzed</span>
<span class="sd">        with the space group analyzer and a refined structure is used</span>
<span class="sd">        :param structure: A pymatgen Structure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">initial_structure</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure_refinement</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">STRUCTURE_REFINEMENT_NONE</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">symmetrized_structure</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">initial_structure</span><span class="p">,</span>
                                                   <span class="n">symprec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_options</span><span class="p">[</span><span class="s1">&#39;symprec&#39;</span><span class="p">],</span>
                                                   <span class="n">angle_tolerance</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_options</span><span class="p">[</span><span class="s1">&#39;angle_tolerance&#39;</span><span class="p">])</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure_refinement</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">STRUCTURE_REFINEMENT_REFINED</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer</span><span class="o">.</span><span class="n">get_refined_structure</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">symmetrized_structure</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure_refinement</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">STRUCTURE_REFINEMENT_SYMMETRIZED</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer</span><span class="o">.</span><span class="n">get_refined_structure</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_refined</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                    <span class="n">symprec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_options</span><span class="p">[</span><span class="s1">&#39;symprec&#39;</span><span class="p">],</span>
                    <span class="n">angle_tolerance</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_options</span><span class="p">[</span><span class="s1">&#39;angle_tolerance&#39;</span><span class="p">])</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">symmetrized_structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_refined</span><span class="o">.</span><span class="n">get_symmetrized_structure</span><span class="p">()</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.get_structure"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.get_structure">[docs]</a>    <span class="k">def</span> <span class="nf">get_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the pymatgen Structure that has been setup for the identification of geometries (the initial one</span>
<span class="sd">        might have been refined/symmetrized using the SpaceGroupAnalyzer).</span>
<span class="sd">        :return: The pymatgen Structure that has been setup for the identification of geometries (the initial one</span>
<span class="sd">        might have been refined/symmetrized using the SpaceGroupAnalyzer).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.set_structure"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.set_structure">[docs]</a>    <span class="k">def</span> <span class="nf">set_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lattice</span><span class="p">,</span> <span class="n">species</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets up the pymatgen structure for which the coordination geometries have to be identified starting from the</span>
<span class="sd">        lattice, the species and the coordinates</span>
<span class="sd">        :param lattice: The lattice of the structure</span>
<span class="sd">        :param species: The species on the sites</span>
<span class="sd">        :param coords: The coordinates of the sites</span>
<span class="sd">        :param coords_are_cartesian: If set to True, the coordinates are given in cartesian coordinates</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setup_structure</span><span class="p">(</span>
            <span class="n">Structure</span><span class="p">(</span><span class="n">lattice</span><span class="p">,</span> <span class="n">species</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="p">))</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.compute_coordination_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.compute_coordination_environments">[docs]</a>    <span class="k">def</span> <span class="nf">compute_coordination_environments</span><span class="p">(</span>
            <span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">only_cations</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">strategy</span><span class="o">=</span><span class="n">DEFAULT_STRATEGY</span><span class="p">,</span>
            <span class="n">valences</span><span class="o">=</span><span class="s1">&#39;bond-valence-analysis&#39;</span><span class="p">,</span> <span class="n">initial_structure_environments</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param structure:</span>
<span class="sd">        :param indices:</span>
<span class="sd">        :param only_cations:</span>
<span class="sd">        :param strategy:</span>
<span class="sd">        :param valences:</span>
<span class="sd">        :param initial_structure_environments:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setup_structure</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">valences</span> <span class="o">==</span> <span class="s1">&#39;bond-valence-analysis&#39;</span><span class="p">:</span>
            <span class="n">bva</span> <span class="o">=</span> <span class="n">BVAnalyzer</span><span class="p">()</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">vals</span> <span class="o">=</span> <span class="n">bva</span><span class="o">.</span><span class="n">get_valences</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="n">vals</span> <span class="o">=</span> <span class="s1">&#39;undefined&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">valences</span> <span class="o">==</span> <span class="s1">&#39;undefined&#39;</span><span class="p">:</span>
                <span class="n">vals</span> <span class="o">=</span> <span class="n">valences</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">valences</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">structure</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Valences do not match the number of sites in the structure&#39;</span><span class="p">)</span>
                <span class="n">vals</span> <span class="o">=</span> <span class="n">valences</span>
        <span class="c1"># TODO: add something to compute only the neighbors sets needed for the strategy.</span>
        <span class="n">se</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">compute_structure_environments</span><span class="p">(</span><span class="n">only_cations</span><span class="o">=</span><span class="n">only_cations</span><span class="p">,</span> <span class="n">only_indices</span><span class="o">=</span><span class="n">indices</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="n">vals</span><span class="p">,</span>
                                                 <span class="n">initial_structure_environments</span><span class="o">=</span><span class="n">initial_structure_environments</span><span class="p">)</span>
        <span class="n">lse</span> <span class="o">=</span> <span class="n">LightStructureEnvironments</span><span class="o">.</span><span class="n">from_structure_environments</span><span class="p">(</span><span class="n">strategy</span><span class="o">=</span><span class="n">strategy</span><span class="p">,</span> <span class="n">structure_environments</span><span class="o">=</span><span class="n">se</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">lse</span><span class="o">.</span><span class="n">coordination_environments</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.compute_structure_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.compute_structure_environments">[docs]</a>    <span class="k">def</span> <span class="nf">compute_structure_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                                       <span class="n">excluded_atoms</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">only_atoms</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">only_cations</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                       <span class="n">only_indices</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">maximum_distance_factor</span><span class="o">=</span><span class="n">PRESETS</span><span class="p">[</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">][</span><span class="s1">&#39;maximum_distance_factor&#39;</span><span class="p">],</span>
                                       <span class="n">minimum_angle_factor</span><span class="o">=</span><span class="n">PRESETS</span><span class="p">[</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">][</span><span class="s1">&#39;minimum_angle_factor&#39;</span><span class="p">],</span>
                                       <span class="n">max_cn</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">min_cn</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">only_symbols</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">valences</span><span class="o">=</span><span class="s1">&#39;undefined&#39;</span><span class="p">,</span>
                                       <span class="n">additional_conditions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">info</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">timelimit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">initial_structure_environments</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">get_from_hints</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                       <span class="n">voronoi_normalized_distance_tolerance</span><span class="o">=</span><span class="n">PRESETS</span><span class="p">[</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">]</span>
                                       <span class="p">[</span><span class="s1">&#39;voronoi_normalized_distance_tolerance&#39;</span><span class="p">],</span>
                                       <span class="n">voronoi_normalized_angle_tolerance</span><span class="o">=</span><span class="n">PRESETS</span><span class="p">[</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">]</span>
                                       <span class="p">[</span><span class="s1">&#39;voronoi_normalized_angle_tolerance&#39;</span><span class="p">],</span>
                                       <span class="n">recompute</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                       <span class="n">optimization</span><span class="o">=</span><span class="n">PRESETS</span><span class="p">[</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">][</span><span class="s1">&#39;optimization&#39;</span><span class="p">]):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Computes and returns the StructureEnvironments object containing all the information about the coordination</span>
<span class="sd">        environments in the structure</span>
<span class="sd">        :param excluded_atoms: Atoms for which the coordination geometries does not have to be identified</span>
<span class="sd">        :param only_atoms: If not set to None, atoms for which the coordination geometries have to be identified</span>
<span class="sd">        :param only_cations: If set to True, will only compute environments for cations</span>
<span class="sd">        :param only_indices: If not set to None, will only compute environments the atoms of the given indices</span>
<span class="sd">        :param maximum_distance_factor: If not set to None, neighbors beyond</span>
<span class="sd">            maximum_distance_factor*closest_neighbor_distance are not considered</span>
<span class="sd">        :param minimum_angle_factor: If not set to None, neighbors for which the angle is lower than</span>
<span class="sd">            minimum_angle_factor*largest_angle_neighbor are not considered</span>
<span class="sd">        :param max_cn: maximum coordination number to be considered</span>
<span class="sd">        :param min_cn: minimum coordination number to be considered</span>
<span class="sd">        :param only_symbols: if not set to None, consider only coordination environments with the given symbols</span>
<span class="sd">        :param valences: valences of the atoms</span>
<span class="sd">        :param additional_conditions: additional conditions to be considered in the bonds (example : only bonds</span>
<span class="sd">            between cation and anion</span>
<span class="sd">        :param info: additional info about the calculation</span>
<span class="sd">        :param timelimit: time limit (in secs) after which the calculation of the StructureEnvironments object stops</span>
<span class="sd">        :param initial_structure_environments: initial StructureEnvironments object (most probably incomplete)</span>
<span class="sd">        :param get_from_hints: whether to add neighbors sets from &quot;hints&quot; (e.g. capped environment =&gt; test the</span>
<span class="sd">            neighbors without the cap)</span>
<span class="sd">        :param voronoi_normalized_distance_tolerance: tolerance for the normalized distance used to distinguish</span>
<span class="sd">            neighbors sets</span>
<span class="sd">        :param voronoi_normalized_angle_tolerance: tolerance for the normalized angle used to distinguish</span>
<span class="sd">            neighbors sets</span>
<span class="sd">        :param recompute: whether to recompute the sites already computed (when initial_structure_environments</span>
<span class="sd">            is not None)</span>
<span class="sd">        :param optimization: optimization algorithm</span>
<span class="sd">        :return: The StructureEnvironments object containing all the information about the coordination</span>
<span class="sd">            environments in the structure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">time_init</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">info</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">info</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">info</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
            <span class="s1">&#39;local_geometry_finder&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;parameters&#39;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s1">&#39;centering_type&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span><span class="p">,</span>
                    <span class="s1">&#39;include_central_site_in_centroid&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span><span class="p">,</span>
                    <span class="s1">&#39;structure_refinement&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure_refinement</span><span class="p">,</span>
                    <span class="s1">&#39;spg_analyzer_options&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">spg_analyzer_options</span>
                <span class="p">}</span>
            <span class="p">}</span>
        <span class="p">})</span>
        <span class="k">if</span> <span class="n">only_symbols</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span> <span class="o">=</span> <span class="n">AllCoordinationGeometries</span><span class="p">(</span>
                <span class="n">permutations_safe_override</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">permutations_safe_override</span><span class="p">,</span>
                <span class="n">only_symbols</span><span class="o">=</span><span class="n">only_symbols</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">valences</span> <span class="o">==</span> <span class="s1">&#39;undefined&#39;</span><span class="p">:</span>
            <span class="n">firstsite</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">sp</span> <span class="o">=</span> <span class="n">firstsite</span><span class="o">.</span><span class="n">specie</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">sp</span><span class="p">,</span> <span class="n">Specie</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">oxi_state</span><span class="p">)</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">=</span> <span class="n">valences</span>
            <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">=</span> <span class="n">valences</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">=</span> <span class="n">valences</span>

        <span class="c1"># Get a list of indices of unequivalent sites from the initial structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">equivalent_sites</span> <span class="o">=</span> <span class="p">[[</span><span class="n">site</span><span class="p">]</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">struct_sites_to_irreducible_site_list_map</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span>
            <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sites_map</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)))</span>
        <span class="n">indices</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)))</span>

        <span class="c1"># Get list of unequivalent sites with valence &gt;= 0</span>
        <span class="k">if</span> <span class="n">only_cations</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">valences</span> <span class="o">!=</span> <span class="s1">&#39;undefined&#39;</span><span class="p">:</span>
            <span class="n">sites_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">isite</span> <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="n">indices</span> <span class="k">if</span>
                             <span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sites_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">isite</span> <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">]</span>

        <span class="c1"># Include atoms that are in the list of &quot;only_atoms&quot; if it is provided</span>
        <span class="k">if</span> <span class="n">only_atoms</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">sites_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">isite</span> <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="n">sites_indices</span>
                             <span class="k">if</span> <span class="nb">any</span><span class="p">([</span><span class="n">at</span> <span class="ow">in</span> <span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">species</span><span class="p">]</span>
                                     <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">only_atoms</span><span class="p">])]</span>

        <span class="c1"># Exclude atoms that are in the list of excluded atoms</span>
        <span class="k">if</span> <span class="n">excluded_atoms</span><span class="p">:</span>
            <span class="n">sites_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">isite</span> <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="n">sites_indices</span>
                             <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">([</span><span class="n">at</span> <span class="ow">in</span> <span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span>
                                                <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">[</span>
                                                    <span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">species</span><span class="p">]</span>
                                         <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">excluded_atoms</span><span class="p">])]</span>

        <span class="k">if</span> <span class="n">only_indices</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">sites_indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">isite</span> <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="n">indices</span> <span class="k">if</span>
                             <span class="n">isite</span> <span class="ow">in</span> <span class="n">only_indices</span><span class="p">]</span>

        <span class="c1"># Get the VoronoiContainer for the sites defined by their indices (sites_indices)</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Getting DetailedVoronoiContainer&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">voronoi_normalized_distance_tolerance</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">normalized_distance_tolerance</span> <span class="o">=</span> <span class="n">DetailedVoronoiContainer</span><span class="o">.</span><span class="n">default_normalized_distance_tolerance</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">normalized_distance_tolerance</span> <span class="o">=</span> <span class="n">voronoi_normalized_distance_tolerance</span>
        <span class="k">if</span> <span class="n">voronoi_normalized_angle_tolerance</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">normalized_angle_tolerance</span> <span class="o">=</span> <span class="n">DetailedVoronoiContainer</span><span class="o">.</span><span class="n">default_normalized_angle_tolerance</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">normalized_angle_tolerance</span> <span class="o">=</span> <span class="n">voronoi_normalized_angle_tolerance</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span> <span class="o">=</span> <span class="n">DetailedVoronoiContainer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                                                         <span class="n">isites</span><span class="o">=</span><span class="n">sites_indices</span><span class="p">,</span>
                                                         <span class="n">valences</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">,</span>
                                                         <span class="n">maximum_distance_factor</span><span class="o">=</span><span class="n">maximum_distance_factor</span><span class="p">,</span>
                                                         <span class="n">minimum_angle_factor</span><span class="o">=</span><span class="n">minimum_angle_factor</span><span class="p">,</span>
                                                         <span class="n">additional_conditions</span><span class="o">=</span><span class="n">additional_conditions</span><span class="p">,</span>
                                                         <span class="n">normalized_distance_tolerance</span><span class="o">=</span><span class="n">normalized_distance_tolerance</span><span class="p">,</span>
                                                         <span class="n">normalized_angle_tolerance</span><span class="o">=</span><span class="n">normalized_angle_tolerance</span><span class="p">)</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;DetailedVoronoiContainer has been set up&#39;</span><span class="p">)</span>

        <span class="c1"># Initialize the StructureEnvironments object (either from initial_structure_environments or from scratch)</span>
        <span class="k">if</span> <span class="n">initial_structure_environments</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">se</span> <span class="o">=</span> <span class="n">initial_structure_environments</span>
            <span class="k">if</span> <span class="n">se</span><span class="o">.</span><span class="n">structure</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Structure is not the same in initial_structure_environments&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">se</span><span class="o">.</span><span class="n">voronoi</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">is_close_to</span><span class="p">(</span><span class="n">se</span><span class="o">.</span><span class="n">voronoi</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span> <span class="o">=</span> <span class="n">se</span><span class="o">.</span><span class="n">voronoi</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Detailed Voronoi is not the same in initial_structure_environments&#39;</span><span class="p">)</span>
            <span class="n">se</span><span class="o">.</span><span class="n">info</span> <span class="o">=</span> <span class="n">info</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">se</span> <span class="o">=</span> <span class="n">StructureEnvironments</span><span class="p">(</span><span class="n">voronoi</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">valences</span><span class="p">,</span>
                                       <span class="n">sites_map</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sites_map</span><span class="p">,</span> <span class="n">equivalent_sites</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">equivalent_sites</span><span class="p">,</span>
                                       <span class="n">ce_list</span><span class="o">=</span><span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">),</span> <span class="n">structure</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
                                       <span class="n">info</span><span class="o">=</span><span class="n">info</span><span class="p">)</span>

        <span class="c1"># Set up the coordination numbers that have to be computed based on min_cn, max_cn and possibly the settings</span>
        <span class="c1"># for an update (argument &quot;recompute&quot;) of an existing StructureEnvironments</span>
        <span class="k">if</span> <span class="n">min_cn</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">min_cn</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="n">max_cn</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">max_cn</span> <span class="o">=</span> <span class="mi">20</span>
        <span class="n">all_cns</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">min_cn</span><span class="p">,</span> <span class="n">max_cn</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">do_recompute</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="n">recompute</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="s1">&#39;cns&#39;</span> <span class="ow">in</span> <span class="n">recompute</span><span class="p">:</span>
                <span class="n">cns_to_recompute</span> <span class="o">=</span> <span class="n">recompute</span><span class="p">[</span><span class="s1">&#39;cns&#39;</span><span class="p">]</span>
                <span class="n">all_cns</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">all_cns</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">cns_to_recompute</span><span class="p">))</span>
            <span class="n">do_recompute</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="c1"># Variables used for checking timelimit</span>
        <span class="n">max_time_one_site</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="n">breakit</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="k">if</span> <span class="n">optimization</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">local_planes</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">separations</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>

        <span class="c1"># Loop on all the sites</span>
        <span class="k">for</span> <span class="n">isite</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">isite</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">sites_indices</span><span class="p">:</span>
                <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39; ... in site #</span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1"> (</span><span class="si">{}</span><span class="s1">) : &#39;</span>
                              <span class="s1">&#39;skipped&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">),</span>
                                               <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">species_string</span><span class="p">))</span>
                <span class="k">continue</span>
            <span class="k">if</span> <span class="n">breakit</span><span class="p">:</span>
                <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39; ... in site #</span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1"> (</span><span class="si">{}</span><span class="s1">) : &#39;</span>
                              <span class="s1">&#39;skipped (timelimit)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">),</span>
                                                           <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">species_string</span><span class="p">))</span>
                <span class="k">continue</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39; ... in site #</span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1"> (</span><span class="si">{}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">),</span>
                                                                <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">species_string</span><span class="p">))</span>
            <span class="n">t1</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">optimization</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">local_planes</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">detailed_voronoi</span><span class="o">.</span><span class="n">separations</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">se</span><span class="o">.</span><span class="n">init_neighbors_sets</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">additional_conditions</span><span class="o">=</span><span class="n">additional_conditions</span><span class="p">,</span> <span class="n">valences</span><span class="o">=</span><span class="n">valences</span><span class="p">)</span>

            <span class="n">to_add_from_hints</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">nb_sets_info</span> <span class="o">=</span> <span class="p">{}</span>

            <span class="k">for</span> <span class="n">cn</span><span class="p">,</span> <span class="n">nb_sets</span> <span class="ow">in</span> <span class="n">se</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">cn</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">all_cns</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">for</span> <span class="n">inb_set</span><span class="p">,</span> <span class="n">nb_set</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">nb_sets</span><span class="p">):</span>
                    <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    ... getting environments for nb_set (</span><span class="si">{:d}</span><span class="s1">, </span><span class="si">{:d}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cn</span><span class="p">,</span> <span class="n">inb_set</span><span class="p">))</span>
                    <span class="n">tnbset1</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
                    <span class="n">ce</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">update_nb_set_environments</span><span class="p">(</span><span class="n">se</span><span class="o">=</span><span class="n">se</span><span class="p">,</span> <span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="o">=</span><span class="n">cn</span><span class="p">,</span> <span class="n">inb_set</span><span class="o">=</span><span class="n">inb_set</span><span class="p">,</span> <span class="n">nb_set</span><span class="o">=</span><span class="n">nb_set</span><span class="p">,</span>
                                                         <span class="n">recompute</span><span class="o">=</span><span class="n">do_recompute</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
                    <span class="n">tnbset2</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
                    <span class="k">if</span> <span class="n">cn</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">nb_sets_info</span><span class="p">:</span>
                        <span class="n">nb_sets_info</span><span class="p">[</span><span class="n">cn</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                    <span class="n">nb_sets_info</span><span class="p">[</span><span class="n">cn</span><span class="p">][</span><span class="n">inb_set</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">tnbset2</span> <span class="o">-</span> <span class="n">tnbset1</span><span class="p">}</span>
                    <span class="k">if</span> <span class="n">get_from_hints</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">cg_symbol</span><span class="p">,</span> <span class="n">cg_dict</span> <span class="ow">in</span> <span class="n">ce</span><span class="p">:</span>
                            <span class="n">cg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="p">[</span><span class="n">cg_symbol</span><span class="p">]</span>
                            <span class="c1"># Get possibly missing neighbors sets</span>
                            <span class="k">if</span> <span class="n">cg</span><span class="o">.</span><span class="n">neighbors_sets_hints</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                                <span class="k">continue</span>
                            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;       ... getting hints from cg with mp_symbol &quot;</span><span class="si">{}</span><span class="s1">&quot; ...&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cg_symbol</span><span class="p">))</span>
                            <span class="n">hints_info</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;csm&#39;</span><span class="p">:</span> <span class="n">cg_dict</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">],</span>
                                          <span class="s1">&#39;nb_set&#39;</span><span class="p">:</span> <span class="n">nb_set</span><span class="p">,</span>
                                          <span class="s1">&#39;permutation&#39;</span><span class="p">:</span> <span class="n">cg_dict</span><span class="p">[</span><span class="s1">&#39;permutation&#39;</span><span class="p">]}</span>
                            <span class="k">for</span> <span class="n">nb_sets_hints</span> <span class="ow">in</span> <span class="n">cg</span><span class="o">.</span><span class="n">neighbors_sets_hints</span><span class="p">:</span>
                                <span class="n">suggested_nb_set_voronoi_indices</span> <span class="o">=</span> <span class="n">nb_sets_hints</span><span class="o">.</span><span class="n">hints</span><span class="p">(</span><span class="n">hints_info</span><span class="p">)</span>
                                <span class="k">for</span> <span class="n">inew</span><span class="p">,</span> <span class="n">new_nb_set_voronoi_indices</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">suggested_nb_set_voronoi_indices</span><span class="p">):</span>
                                    <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;           hint # </span><span class="si">{:d}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">inew</span><span class="p">))</span>
                                    <span class="n">new_nb_set</span> <span class="o">=</span> <span class="n">se</span><span class="o">.</span><span class="n">NeighborsSet</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">se</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span>
                                                                 <span class="n">detailed_voronoi</span><span class="o">=</span><span class="n">se</span><span class="o">.</span><span class="n">voronoi</span><span class="p">,</span>
                                                                 <span class="n">site_voronoi_indices</span><span class="o">=</span><span class="n">new_nb_set_voronoi_indices</span><span class="p">,</span>
                                                                 <span class="n">sources</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;origin&#39;</span><span class="p">:</span> <span class="s1">&#39;nb_set_hints&#39;</span><span class="p">,</span>
                                                                          <span class="s1">&#39;hints_type&#39;</span><span class="p">:</span> <span class="n">nb_sets_hints</span><span class="o">.</span><span class="n">hints_type</span><span class="p">,</span>
                                                                          <span class="s1">&#39;suggestion_index&#39;</span><span class="p">:</span> <span class="n">inew</span><span class="p">,</span>
                                                                          <span class="s1">&#39;cn_map_source&#39;</span><span class="p">:</span> <span class="p">[</span><span class="n">cn</span><span class="p">,</span> <span class="n">inb_set</span><span class="p">],</span>
                                                                          <span class="s1">&#39;cg_source_symbol&#39;</span><span class="p">:</span> <span class="n">cg_symbol</span><span class="p">})</span>
                                    <span class="n">cn_new_nb_set</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">new_nb_set</span><span class="p">)</span>
                                    <span class="k">if</span> <span class="n">max_cn</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">cn_new_nb_set</span> <span class="o">&gt;</span> <span class="n">max_cn</span><span class="p">:</span>
                                        <span class="k">continue</span>
                                    <span class="k">if</span> <span class="n">min_cn</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">cn_new_nb_set</span> <span class="o">&lt;</span> <span class="n">min_cn</span><span class="p">:</span>
                                        <span class="k">continue</span>
                                    <span class="k">if</span> <span class="n">new_nb_set</span> <span class="ow">in</span> <span class="p">[</span><span class="n">ta</span><span class="p">[</span><span class="s1">&#39;new_nb_set&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">ta</span> <span class="ow">in</span> <span class="n">to_add_from_hints</span><span class="p">]:</span>
                                        <span class="n">has_nb_set</span> <span class="o">=</span> <span class="kc">True</span>
                                    <span class="k">elif</span> <span class="n">cn_new_nb_set</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">se</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">]:</span>
                                        <span class="n">has_nb_set</span> <span class="o">=</span> <span class="kc">False</span>
                                    <span class="k">else</span><span class="p">:</span>
                                        <span class="n">has_nb_set</span> <span class="o">=</span> <span class="n">new_nb_set</span> <span class="ow">in</span> <span class="n">se</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite</span><span class="p">][</span><span class="n">cn_new_nb_set</span><span class="p">]</span>
                                    <span class="k">if</span> <span class="ow">not</span> <span class="n">has_nb_set</span><span class="p">:</span>
                                        <span class="n">to_add_from_hints</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;isite&#39;</span><span class="p">:</span> <span class="n">isite</span><span class="p">,</span>
                                                                  <span class="s1">&#39;new_nb_set&#39;</span><span class="p">:</span> <span class="n">new_nb_set</span><span class="p">,</span>
                                                                  <span class="s1">&#39;cn_new_nb_set&#39;</span><span class="p">:</span> <span class="n">cn_new_nb_set</span><span class="p">})</span>
                                        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;              =&gt; to be computed&#39;</span><span class="p">)</span>
                                    <span class="k">else</span><span class="p">:</span>
                                        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;              =&gt; already present&#39;</span><span class="p">)</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    ... getting environments for nb_sets added from hints&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">missing_nb_set_to_add</span> <span class="ow">in</span> <span class="n">to_add_from_hints</span><span class="p">:</span>
                <span class="n">se</span><span class="o">.</span><span class="n">add_neighbors_set</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">nb_set</span><span class="o">=</span><span class="n">missing_nb_set_to_add</span><span class="p">[</span><span class="s1">&#39;new_nb_set&#39;</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">missing_nb_set_to_add</span> <span class="ow">in</span> <span class="n">to_add_from_hints</span><span class="p">:</span>
                <span class="n">isite_new_nb_set</span> <span class="o">=</span> <span class="n">missing_nb_set_to_add</span><span class="p">[</span><span class="s1">&#39;isite&#39;</span><span class="p">]</span>
                <span class="n">cn_new_nb_set</span> <span class="o">=</span> <span class="n">missing_nb_set_to_add</span><span class="p">[</span><span class="s1">&#39;cn_new_nb_set&#39;</span><span class="p">]</span>
                <span class="n">new_nb_set</span> <span class="o">=</span> <span class="n">missing_nb_set_to_add</span><span class="p">[</span><span class="s1">&#39;new_nb_set&#39;</span><span class="p">]</span>
                <span class="n">inew_nb_set</span> <span class="o">=</span> <span class="n">se</span><span class="o">.</span><span class="n">neighbors_sets</span><span class="p">[</span><span class="n">isite_new_nb_set</span><span class="p">][</span><span class="n">cn_new_nb_set</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">new_nb_set</span><span class="p">)</span>
                <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    ... getting environments for nb_set (</span><span class="si">{:d}</span><span class="s1">, </span><span class="si">{:d}</span><span class="s1">) - &#39;</span>
                              <span class="s1">&#39;from hints&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cn_new_nb_set</span><span class="p">,</span> <span class="n">inew_nb_set</span><span class="p">))</span>
                <span class="n">tnbset1</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">update_nb_set_environments</span><span class="p">(</span><span class="n">se</span><span class="o">=</span><span class="n">se</span><span class="p">,</span>
                                                <span class="n">isite</span><span class="o">=</span><span class="n">isite_new_nb_set</span><span class="p">,</span>
                                                <span class="n">cn</span><span class="o">=</span><span class="n">cn_new_nb_set</span><span class="p">,</span>
                                                <span class="n">inb_set</span><span class="o">=</span><span class="n">inew_nb_set</span><span class="p">,</span>
                                                <span class="n">nb_set</span><span class="o">=</span><span class="n">new_nb_set</span><span class="p">,</span>
                                                <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
                <span class="n">tnbset2</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">cn</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">nb_sets_info</span><span class="p">:</span>
                    <span class="n">nb_sets_info</span><span class="p">[</span><span class="n">cn</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">nb_sets_info</span><span class="p">[</span><span class="n">cn</span><span class="p">][</span><span class="n">inew_nb_set</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">tnbset2</span> <span class="o">-</span> <span class="n">tnbset1</span><span class="p">}</span>
            <span class="n">t2</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
            <span class="n">se</span><span class="o">.</span><span class="n">update_site_info</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">info_dict</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;time&#39;</span><span class="p">:</span> <span class="n">t2</span> <span class="o">-</span> <span class="n">t1</span><span class="p">,</span> <span class="s1">&#39;nb_sets_info&#39;</span><span class="p">:</span> <span class="n">nb_sets_info</span><span class="p">})</span>
            <span class="k">if</span> <span class="n">timelimit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">time_elapsed</span> <span class="o">=</span> <span class="n">t2</span> <span class="o">-</span> <span class="n">time_init</span>
                <span class="n">time_left</span> <span class="o">=</span> <span class="n">timelimit</span> <span class="o">-</span> <span class="n">time_elapsed</span>
                <span class="k">if</span> <span class="n">time_left</span> <span class="o">&lt;</span> <span class="mf">2.0</span> <span class="o">*</span> <span class="n">max_time_one_site</span><span class="p">:</span>
                    <span class="n">breakit</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="n">max_time_one_site</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">max_time_one_site</span><span class="p">,</span> <span class="n">t2</span> <span class="o">-</span> <span class="n">t1</span><span class="p">)</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    ... computed in </span><span class="si">{:.2f}</span><span class="s1"> seconds&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t2</span> <span class="o">-</span> <span class="n">t1</span><span class="p">))</span>
        <span class="n">time_end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">process_time</span><span class="p">()</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;    ... compute_structure_environments ended in </span><span class="si">{:.2f}</span><span class="s1"> seconds&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time_end</span> <span class="o">-</span> <span class="n">time_init</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">se</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.update_nb_set_environments"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.update_nb_set_environments">[docs]</a>    <span class="k">def</span> <span class="nf">update_nb_set_environments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">se</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="p">,</span> <span class="n">inb_set</span><span class="p">,</span> <span class="n">nb_set</span><span class="p">,</span> <span class="n">recompute</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param se:</span>
<span class="sd">        :param isite:</span>
<span class="sd">        :param cn:</span>
<span class="sd">        :param inb_set:</span>
<span class="sd">        :param nb_set:</span>
<span class="sd">        :param recompute:</span>
<span class="sd">        :param optimization:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ce</span> <span class="o">=</span> <span class="n">se</span><span class="o">.</span><span class="n">get_coordination_environments</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="o">=</span><span class="n">cn</span><span class="p">,</span> <span class="n">nb_set</span><span class="o">=</span><span class="n">nb_set</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ce</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">recompute</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">ce</span>
        <span class="n">ce</span> <span class="o">=</span> <span class="n">ChemicalEnvironments</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">optimization</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">neighb_coords</span> <span class="o">=</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">neighb_coordsOpt</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">neighb_coords</span> <span class="o">=</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">neighb_coords</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setup_local_geometry</span><span class="p">(</span><span class="n">isite</span><span class="p">,</span> <span class="n">coords</span><span class="o">=</span><span class="n">neighb_coords</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">optimization</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Getting StructureEnvironments with optimized algorithm&#39;</span><span class="p">)</span>
            <span class="n">nb_set</span><span class="o">.</span><span class="n">local_planes</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
            <span class="n">nb_set</span><span class="o">.</span><span class="n">separations</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">cncgsm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_coordination_symmetry_measures_optim</span><span class="p">(</span><span class="n">nb_set</span><span class="o">=</span><span class="n">nb_set</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Getting StructureEnvironments with standard algorithm&#39;</span><span class="p">)</span>
            <span class="n">cncgsm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_coordination_symmetry_measures</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">cncgsm</span><span class="p">:</span>
            <span class="n">other_csms</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s1">&#39;csm_wocs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;csm_wocs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;csm_wocs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;csm_wocs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;csm_wocs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;csm_wocs_csc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;csm_wcs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;csm_wcs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;csm_wcs_csc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;rotation_matrix_wocs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wocs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;rotation_matrix_wocs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wocs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;rotation_matrix_wocs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wocs_csc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;rotation_matrix_wcs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wcs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;rotation_matrix_wcs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wcs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;rotation_matrix_wcs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wcs_csc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;scaling_factor_wocs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wocs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;scaling_factor_wocs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wocs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;scaling_factor_wocs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wocs_csc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;scaling_factor_wcs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wcs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;scaling_factor_wcs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wcs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;scaling_factor_wcs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wcs_csc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;translation_vector_wocs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;translation_vector_wocs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;translation_vector_wocs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;translation_vector_wocs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;translation_vector_wocs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;translation_vector_wocs_csc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;translation_vector_wcs_ctwocc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;translation_vector_wcs_ctwocc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;translation_vector_wcs_ctwcc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;translation_vector_wcs_ctwcc&#39;</span><span class="p">],</span>
                <span class="s1">&#39;translation_vector_wcs_csc&#39;</span><span class="p">:</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;translation_vector_wcs_csc&#39;</span><span class="p">]</span>
            <span class="p">}</span>
            <span class="n">ce</span><span class="o">.</span><span class="n">add_coord_geom</span><span class="p">(</span><span class="n">cg</span><span class="p">,</span> <span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;csm&#39;</span><span class="p">],</span>
                              <span class="n">algo</span><span class="o">=</span><span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;algo&#39;</span><span class="p">],</span>
                              <span class="n">permutation</span><span class="o">=</span><span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;indices&#39;</span><span class="p">],</span>
                              <span class="n">local2perfect_map</span><span class="o">=</span><span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span>
                                  <span class="s1">&#39;local2perfect_map&#39;</span><span class="p">],</span>
                              <span class="n">perfect2local_map</span><span class="o">=</span><span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span>
                                  <span class="s1">&#39;perfect2local_map&#39;</span><span class="p">],</span>
                              <span class="n">detailed_voronoi_index</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;cn&#39;</span><span class="p">:</span> <span class="n">cn</span><span class="p">,</span>
                                                      <span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="n">inb_set</span><span class="p">},</span>
                              <span class="n">other_symmetry_measures</span><span class="o">=</span><span class="n">other_csms</span><span class="p">,</span>
                              <span class="n">rotation_matrix</span><span class="o">=</span><span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">],</span>
                              <span class="n">scaling_factor</span><span class="o">=</span><span class="n">cncgsm</span><span class="p">[</span><span class="n">cg</span><span class="p">][</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">]</span>
                              <span class="p">)</span>
        <span class="n">se</span><span class="o">.</span><span class="n">update_coordination_environments</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="n">isite</span><span class="p">,</span> <span class="n">cn</span><span class="o">=</span><span class="n">cn</span><span class="p">,</span> <span class="n">nb_set</span><span class="o">=</span><span class="n">nb_set</span><span class="p">,</span> <span class="n">ce</span><span class="o">=</span><span class="n">ce</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">ce</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_local_geometry"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_local_geometry">[docs]</a>    <span class="k">def</span> <span class="nf">setup_local_geometry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">isite</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets up the AbstractGeometry for the local geometry of site with index isite.</span>
<span class="sd">        :param isite: Index of the site for which the local geometry has to be set up</span>
<span class="sd">        :param coords: The coordinates of the (local) neighbors</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span> <span class="o">=</span> <span class="n">AbstractGeometry</span><span class="p">(</span>
            <span class="n">central_site</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">cart_coords</span><span class="p">[</span><span class="n">isite</span><span class="p">],</span>
            <span class="n">bare_coords</span><span class="o">=</span><span class="n">coords</span><span class="p">,</span>
            <span class="n">centering_type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span><span class="p">,</span>
            <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span><span class="p">,</span>
            <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_test_perfect_environment"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_test_perfect_environment">[docs]</a>    <span class="k">def</span> <span class="nf">setup_test_perfect_environment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbol</span><span class="p">,</span> <span class="n">randomness</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                       <span class="n">max_random_dist</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span>
                                       <span class="n">symbol_type</span><span class="o">=</span><span class="s1">&#39;mp_symbol&#39;</span><span class="p">,</span>
                                       <span class="n">indices</span><span class="o">=</span><span class="s1">&#39;RANDOM&#39;</span><span class="p">,</span>
                                       <span class="n">random_translation</span><span class="o">=</span><span class="s1">&#39;NONE&#39;</span><span class="p">,</span>
                                       <span class="n">random_rotation</span><span class="o">=</span><span class="s1">&#39;NONE&#39;</span><span class="p">,</span>
                                       <span class="n">random_scale</span><span class="o">=</span><span class="s1">&#39;NONE&#39;</span><span class="p">,</span>
                                       <span class="n">points</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param symbol:</span>
<span class="sd">        :param randomness:</span>
<span class="sd">        :param max_random_dist:</span>
<span class="sd">        :param symbol_type:</span>
<span class="sd">        :param indices:</span>
<span class="sd">        :param random_translation:</span>
<span class="sd">        :param random_rotation:</span>
<span class="sd">        :param random_scale:</span>
<span class="sd">        :param points:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">symbol_type</span> <span class="o">==</span> <span class="s1">&#39;IUPAC&#39;</span><span class="p">:</span>
            <span class="n">cg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">get_geometry_from_IUPAC_symbol</span><span class="p">(</span><span class="n">symbol</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">symbol_type</span> <span class="o">==</span> <span class="s1">&#39;MP&#39;</span> <span class="ow">or</span> <span class="n">symbol_type</span> <span class="o">==</span> <span class="s1">&#39;mp_symbol&#39;</span><span class="p">:</span>
            <span class="n">cg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">get_geometry_from_mp_symbol</span><span class="p">(</span><span class="n">symbol</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">symbol_type</span> <span class="o">==</span> <span class="s1">&#39;CoordinationGeometry&#39;</span><span class="p">:</span>
            <span class="n">cg</span> <span class="o">=</span> <span class="n">symbol</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Wrong mp_symbol to setup coordination geometry&#39;</span><span class="p">)</span>
        <span class="n">neighb_coords</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">points</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">mypoints</span> <span class="o">=</span> <span class="n">points</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mypoints</span> <span class="o">=</span> <span class="n">cg</span><span class="o">.</span><span class="n">points</span>
        <span class="k">if</span> <span class="n">randomness</span><span class="p">:</span>
            <span class="n">rv</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
            <span class="k">while</span> <span class="n">norm</span><span class="p">(</span><span class="n">rv</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">1.0</span><span class="p">:</span>
                <span class="n">rv</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span> <span class="o">+</span> <span class="n">max_random_dist</span> <span class="o">*</span> <span class="n">rv</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">pp</span> <span class="ow">in</span> <span class="n">mypoints</span><span class="p">:</span>
                <span class="n">rv</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
                <span class="k">while</span> <span class="n">norm</span><span class="p">(</span><span class="n">rv</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">1.0</span><span class="p">:</span>
                    <span class="n">rv</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
                <span class="n">neighb_coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">pp</span><span class="p">)</span> <span class="o">+</span> <span class="n">max_random_dist</span> <span class="o">*</span> <span class="n">rv</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)]</span>
            <span class="k">for</span> <span class="n">pp</span> <span class="ow">in</span> <span class="n">mypoints</span><span class="p">:</span>
                <span class="n">neighb_coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">pp</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">indices</span> <span class="o">==</span> <span class="s1">&#39;RANDOM&#39;</span><span class="p">:</span>
            <span class="n">shuffle</span><span class="p">(</span><span class="n">neighb_coords</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">indices</span> <span class="o">==</span> <span class="s1">&#39;ORDERED&#39;</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">neighb_coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">neighb_coords</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">indices</span><span class="p">]</span>

        <span class="c1"># Scaling the test environment</span>
        <span class="k">if</span> <span class="n">random_scale</span> <span class="o">==</span> <span class="s1">&#39;RANDOM&#39;</span><span class="p">:</span>
            <span class="n">scale</span> <span class="o">=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">()</span> <span class="o">+</span> <span class="mf">0.95</span>
        <span class="k">elif</span> <span class="n">random_scale</span> <span class="o">==</span> <span class="s1">&#39;NONE&#39;</span><span class="p">:</span>
            <span class="n">scale</span> <span class="o">=</span> <span class="mf">1.0</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">scale</span> <span class="o">=</span> <span class="n">random_scale</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">scale</span> <span class="o">*</span> <span class="n">cc</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">]</span>
        <span class="n">neighb_coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">scale</span> <span class="o">*</span> <span class="n">cc</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">neighb_coords</span><span class="p">]</span>

        <span class="c1"># Rotating the test environment</span>
        <span class="k">if</span> <span class="n">random_rotation</span> <span class="o">==</span> <span class="s1">&#39;RANDOM&#39;</span><span class="p">:</span>
            <span class="n">uu</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.1</span>
            <span class="n">uu</span> <span class="o">=</span> <span class="n">uu</span> <span class="o">/</span> <span class="n">norm</span><span class="p">(</span><span class="n">uu</span><span class="p">)</span>
            <span class="n">theta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">()</span>
            <span class="n">cc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
            <span class="n">ss</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
            <span class="n">ux</span> <span class="o">=</span> <span class="n">uu</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">uy</span> <span class="o">=</span> <span class="n">uu</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">uz</span> <span class="o">=</span> <span class="n">uu</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">RR</span> <span class="o">=</span> <span class="p">[[</span><span class="n">ux</span> <span class="o">*</span> <span class="n">ux</span> <span class="o">+</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">ux</span> <span class="o">*</span> <span class="n">ux</span><span class="p">)</span> <span class="o">*</span> <span class="n">cc</span><span class="p">,</span> <span class="n">ux</span> <span class="o">*</span> <span class="n">uy</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">cc</span><span class="p">)</span> <span class="o">-</span> <span class="n">uz</span> <span class="o">*</span> <span class="n">ss</span><span class="p">,</span> <span class="n">ux</span> <span class="o">*</span> <span class="n">uz</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">cc</span><span class="p">)</span> <span class="o">+</span> <span class="n">uy</span> <span class="o">*</span> <span class="n">ss</span><span class="p">],</span>
                  <span class="p">[</span><span class="n">ux</span> <span class="o">*</span> <span class="n">uy</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">cc</span><span class="p">)</span> <span class="o">+</span> <span class="n">uz</span> <span class="o">*</span> <span class="n">ss</span><span class="p">,</span> <span class="n">uy</span> <span class="o">*</span> <span class="n">uy</span> <span class="o">+</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">uy</span> <span class="o">*</span> <span class="n">uy</span><span class="p">)</span> <span class="o">*</span> <span class="n">cc</span><span class="p">,</span> <span class="n">uy</span> <span class="o">*</span> <span class="n">uz</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">cc</span><span class="p">)</span> <span class="o">-</span> <span class="n">ux</span> <span class="o">*</span> <span class="n">ss</span><span class="p">],</span>
                  <span class="p">[</span><span class="n">ux</span> <span class="o">*</span> <span class="n">uz</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">cc</span><span class="p">)</span> <span class="o">-</span> <span class="n">uy</span> <span class="o">*</span> <span class="n">ss</span><span class="p">,</span> <span class="n">uy</span> <span class="o">*</span> <span class="n">uz</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">cc</span><span class="p">)</span> <span class="o">+</span> <span class="n">ux</span> <span class="o">*</span> <span class="n">ss</span><span class="p">,</span> <span class="n">uz</span> <span class="o">*</span> <span class="n">uz</span> <span class="o">+</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">uz</span> <span class="o">*</span> <span class="n">uz</span><span class="p">)</span> <span class="o">*</span> <span class="n">cc</span><span class="p">]]</span>
        <span class="k">elif</span> <span class="n">random_rotation</span> <span class="o">==</span> <span class="s1">&#39;NONE&#39;</span><span class="p">:</span>
            <span class="n">RR</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span>
                  <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span>
                  <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">RR</span> <span class="o">=</span> <span class="n">random_rotation</span>
        <span class="n">newcoords</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">:</span>
            <span class="n">newcc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">RR</span><span class="p">,</span> <span class="n">cc</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
            <span class="n">newcoords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">newcc</span><span class="o">.</span><span class="n">ravel</span><span class="p">())</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="n">newcoords</span>
        <span class="n">newcoords</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">neighb_coords</span><span class="p">:</span>
            <span class="n">newcc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">RR</span><span class="p">,</span> <span class="n">cc</span><span class="o">.</span><span class="n">T</span><span class="p">)</span>
            <span class="n">newcoords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">newcc</span><span class="o">.</span><span class="n">ravel</span><span class="p">())</span>
        <span class="n">neighb_coords</span> <span class="o">=</span> <span class="n">newcoords</span>

        <span class="c1"># Translating the test environment</span>
        <span class="k">if</span> <span class="n">random_translation</span> <span class="o">==</span> <span class="s1">&#39;RANDOM&#39;</span><span class="p">:</span>
            <span class="n">translation</span> <span class="o">=</span> <span class="mf">10.0</span> <span class="o">*</span> <span class="p">(</span><span class="mf">2.0</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">random_translation</span> <span class="o">==</span> <span class="s1">&#39;NONE&#39;</span><span class="p">:</span>
            <span class="n">translation</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">translation</span> <span class="o">=</span> <span class="n">random_translation</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">cc</span> <span class="o">+</span> <span class="n">translation</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">]</span>
        <span class="n">neighb_coords</span> <span class="o">=</span> <span class="p">[</span><span class="n">cc</span> <span class="o">+</span> <span class="n">translation</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">neighb_coords</span><span class="p">]</span>

        <span class="n">coords</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">neighb_coords</span><span class="p">)</span>
        <span class="n">myspecies</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;O&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">coords</span><span class="p">))</span>
        <span class="n">myspecies</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;Cu&quot;</span>

        <span class="n">amin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">([</span><span class="n">cc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
        <span class="n">amax</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="n">cc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
        <span class="n">bmin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">([</span><span class="n">cc</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
        <span class="n">bmax</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="n">cc</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
        <span class="n">cmin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">([</span><span class="n">cc</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
        <span class="n">cmax</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="n">cc</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">for</span> <span class="n">cc</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>

        <span class="n">factor</span> <span class="o">=</span> <span class="mf">5.0</span>
        <span class="n">aa</span> <span class="o">=</span> <span class="n">factor</span> <span class="o">*</span> <span class="nb">max</span><span class="p">([</span><span class="n">amax</span> <span class="o">-</span> <span class="n">amin</span><span class="p">,</span> <span class="n">bmax</span> <span class="o">-</span> <span class="n">bmin</span><span class="p">,</span> <span class="n">cmax</span> <span class="o">-</span> <span class="n">cmin</span><span class="p">])</span>

        <span class="n">lattice</span> <span class="o">=</span> <span class="n">Lattice</span><span class="o">.</span><span class="n">cubic</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">aa</span><span class="p">)</span>
        <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="n">lattice</span><span class="o">=</span><span class="n">lattice</span><span class="p">,</span> <span class="n">species</span><span class="o">=</span><span class="n">myspecies</span><span class="p">,</span> <span class="n">coords</span><span class="o">=</span><span class="n">coords</span><span class="p">,</span>
                              <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">setup_structure</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setup_local_geometry</span><span class="p">(</span><span class="n">isite</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">coords</span><span class="o">=</span><span class="n">neighb_coords</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span> <span class="o">=</span> <span class="n">AbstractGeometry</span><span class="o">.</span><span class="n">from_cg</span><span class="p">(</span><span class="n">cg</span><span class="o">=</span><span class="n">cg</span><span class="p">)</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_random_structure"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_random_structure">[docs]</a>    <span class="k">def</span> <span class="nf">setup_random_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets up a purely random structure with a given coordination.</span>
<span class="sd">        :param coordination: coordination number for the random structure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">aa</span> <span class="o">=</span> <span class="mf">0.4</span>
        <span class="n">bb</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.2</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">coordination</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
            <span class="n">coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">aa</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="p">)</span> <span class="o">+</span> <span class="n">bb</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span>
            <span class="n">lattice</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">]],</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">),</span>
            <span class="n">species</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;Si&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="n">coordination</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span>
            <span class="n">coords</span><span class="o">=</span><span class="n">coords</span><span class="p">,</span>
            <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setup_random_indices_local_geometry</span><span class="p">(</span><span class="n">coordination</span><span class="p">)</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_random_indices_local_geometry"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_random_indices_local_geometry">[docs]</a>    <span class="k">def</span> <span class="nf">setup_random_indices_local_geometry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets up random indices for the local geometry, for testing purposes</span>
<span class="sd">        :param coordination: coordination of the local geometry</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">icentral_site</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">coordination</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
        <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">indices</span><span class="p">)</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_ordered_indices_local_geometry"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_ordered_indices_local_geometry">[docs]</a>    <span class="k">def</span> <span class="nf">setup_ordered_indices_local_geometry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets up ordered indices for the local geometry, for testing purposes</span>
<span class="sd">        :param coordination: coordination of the local geometry</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">icentral_site</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">coordination</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.setup_explicit_indices_local_geometry"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.setup_explicit_indices_local_geometry">[docs]</a>    <span class="k">def</span> <span class="nf">setup_explicit_indices_local_geometry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">explicit_indices</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets up explicit indices for the local geometry, for testing purposes</span>
<span class="sd">        :param explicit_indices: explicit indices for the neighbors (set of numbers</span>
<span class="sd">        from 0 to CN-1 in a given order)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">icentral_site</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="p">[</span><span class="n">ii</span> <span class="o">+</span> <span class="mi">1</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">explicit_indices</span><span class="p">]</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.get_coordination_symmetry_measures"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.get_coordination_symmetry_measures">[docs]</a>    <span class="k">def</span> <span class="nf">get_coordination_symmetry_measures</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">only_minimum</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                           <span class="n">all_csms</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the continuous symmetry measures of the current local geometry in a dictionary.</span>
<span class="sd">        :return: the continuous symmetry measures of the current local geometry in a dictionary.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">test_geometries</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">get_implemented_geometries</span><span class="p">(</span>
            <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="p">))</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">test_geometries</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">{}</span>
            <span class="n">result_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;S:1&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;csm&#39;</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span> <span class="s1">&#39;indices&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;algo&#39;</span><span class="p">:</span> <span class="s1">&#39;EXPLICIT&#39;</span><span class="p">,</span>
                                   <span class="s1">&#39;local2perfect_map&#39;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mi">0</span><span class="p">},</span> <span class="s1">&#39;perfect2local_map&#39;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mi">0</span><span class="p">},</span>
                                   <span class="s1">&#39;scaling_factor&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;rotation_matrix&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;translation_vector&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}}</span>
            <span class="k">if</span> <span class="n">all_csms</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">csmtype</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;wocs_ctwocc&#39;</span><span class="p">,</span> <span class="s1">&#39;wocs_ctwcc&#39;</span><span class="p">,</span> <span class="s1">&#39;wocs_csc&#39;</span><span class="p">,</span> <span class="s1">&#39;wcs_ctwocc&#39;</span><span class="p">,</span> <span class="s1">&#39;wcs_ctwcc&#39;</span><span class="p">,</span> <span class="s1">&#39;wcs_csc&#39;</span><span class="p">]:</span>
                    <span class="n">result_dict</span><span class="p">[</span><span class="s1">&#39;S:1&#39;</span><span class="p">][</span><span class="s1">&#39;csm_</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">csmtype</span><span class="p">)]</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="n">result_dict</span><span class="p">[</span><span class="s1">&#39;S:1&#39;</span><span class="p">][</span><span class="s1">&#39;scaling_factor_</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">csmtype</span><span class="p">)]</span> <span class="o">=</span> <span class="kc">None</span>
                    <span class="n">result_dict</span><span class="p">[</span><span class="s1">&#39;S:1&#39;</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">csmtype</span><span class="p">)]</span> <span class="o">=</span> <span class="kc">None</span>
                    <span class="n">result_dict</span><span class="p">[</span><span class="s1">&#39;S:1&#39;</span><span class="p">][</span><span class="s1">&#39;translation_vector_</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">csmtype</span><span class="p">)]</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">return</span> <span class="n">result_dict</span>
        <span class="n">result_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">geometry</span> <span class="ow">in</span> <span class="n">test_geometries</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span> <span class="o">=</span> <span class="n">AbstractGeometry</span><span class="o">.</span><span class="n">from_cg</span><span class="p">(</span>
                <span class="n">cg</span><span class="o">=</span><span class="n">geometry</span><span class="p">,</span>
                <span class="n">centering_type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span><span class="p">,</span>
                <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span><span class="p">)</span>
            <span class="n">points_perfect</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">()</span>
            <span class="n">cgsm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_geometry_symmetry_measures</span><span class="p">(</span><span class="n">geometry</span><span class="p">,</span>
                                                                <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">,</span>
                                                                <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
            <span class="n">result</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="n">cgsm</span>
            <span class="k">if</span> <span class="n">only_minimum</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">result</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">imin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">([</span><span class="n">rr</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">rr</span> <span class="ow">in</span> <span class="n">result</span><span class="p">])</span>
                    <span class="k">if</span> <span class="n">geometry</span><span class="o">.</span><span class="n">algorithms</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="n">algo</span> <span class="o">=</span> <span class="n">algos</span><span class="p">[</span><span class="n">imin</span><span class="p">]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">algo</span> <span class="o">=</span> <span class="n">algos</span>
                    <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;csm&#39;</span><span class="p">:</span> <span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">],</span>
                                                       <span class="s1">&#39;indices&#39;</span><span class="p">:</span> <span class="n">permutations</span><span class="p">[</span>
                                                           <span class="n">imin</span><span class="p">],</span>
                                                       <span class="s1">&#39;algo&#39;</span><span class="p">:</span> <span class="n">algo</span><span class="p">,</span>
                                                       <span class="s1">&#39;local2perfect_map&#39;</span><span class="p">:</span>
                                                           <span class="n">local2perfect_maps</span><span class="p">[</span>
                                                               <span class="n">imin</span><span class="p">],</span>
                                                       <span class="s1">&#39;perfect2local_map&#39;</span><span class="p">:</span>
                                                           <span class="n">perfect2local_maps</span><span class="p">[</span>
                                                               <span class="n">imin</span><span class="p">],</span>
                                                       <span class="s1">&#39;scaling_factor&#39;</span><span class="p">:</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">],</span>
                                                       <span class="s1">&#39;rotation_matrix&#39;</span><span class="p">:</span>
                                                           <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">]),</span>
                                                       <span class="s1">&#39;translation_vector&#39;</span><span class="p">:</span> <span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]}</span>
                    <span class="k">if</span> <span class="n">all_csms</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_update_results_all_csms</span><span class="p">(</span><span class="n">result_dict</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">imin</span><span class="p">,</span> <span class="n">geometry</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;csm&#39;</span><span class="p">:</span> <span class="n">result</span><span class="p">,</span>
                                                   <span class="s1">&#39;indices&#39;</span><span class="p">:</span> <span class="n">permutations</span><span class="p">,</span>
                                                   <span class="s1">&#39;algo&#39;</span><span class="p">:</span> <span class="n">algos</span><span class="p">,</span>
                                                   <span class="s1">&#39;local2perfect_map&#39;</span><span class="p">:</span> <span class="n">local2perfect_maps</span><span class="p">,</span>
                                                   <span class="s1">&#39;perfect2local_map&#39;</span><span class="p">:</span> <span class="n">perfect2local_maps</span><span class="p">}</span>
        <span class="k">return</span> <span class="n">result_dict</span></div>

    <span class="k">def</span> <span class="nf">_update_results_all_csms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">result_dict</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">imin</span><span class="p">,</span> <span class="n">geometry</span><span class="p">):</span>
        <span class="n">permutation</span> <span class="o">=</span> <span class="n">permutations</span><span class="p">[</span><span class="n">imin</span><span class="p">]</span>
        <span class="c1"># Without central site, centered on the centroid (centroid does not include the central site)</span>
        <span class="c1"># result_dict[geometry.mp_symbol][&#39;csm_wocs_ctwocc&#39;] = \</span>
        <span class="c1"># result[imin]</span>
        <span class="n">pdist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wocs_ctwocc</span><span class="p">(</span>
            <span class="n">permutation</span><span class="o">=</span><span class="n">permutation</span><span class="p">)</span>
        <span class="n">pperf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wocs_ctwocc</span><span class="p">()</span>
        <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">pdist</span><span class="p">,</span>
                                   <span class="n">points_perfect</span><span class="o">=</span><span class="n">pperf</span><span class="p">)</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;csm_wocs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wocs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">])</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wocs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;translation_vector_wocs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_without_centre</span>
        <span class="c1"># Without central site, centered on the centroid (centroid includes the central site)</span>
        <span class="n">pdist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wocs_ctwcc</span><span class="p">(</span>
            <span class="n">permutation</span><span class="o">=</span><span class="n">permutation</span><span class="p">)</span>
        <span class="n">pperf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wocs_ctwcc</span><span class="p">()</span>
        <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">pdist</span><span class="p">,</span>
                                   <span class="n">points_perfect</span><span class="o">=</span><span class="n">pperf</span><span class="p">)</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;csm_wocs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wocs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">])</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wocs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;translation_vector_wocs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>
        <span class="c1"># Without central site, centered on the central site</span>
        <span class="n">pdist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wocs_csc</span><span class="p">(</span>
            <span class="n">permutation</span><span class="o">=</span><span class="n">permutation</span><span class="p">)</span>
        <span class="n">pperf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wocs_csc</span><span class="p">()</span>
        <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">pdist</span><span class="p">,</span>
                                   <span class="n">points_perfect</span><span class="o">=</span><span class="n">pperf</span><span class="p">)</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;csm_wocs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wocs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">])</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wocs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;translation_vector_wocs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">bare_centre</span>
        <span class="c1"># With central site, centered on the centroid (centroid does not include the central site)</span>
        <span class="n">pdist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwocc</span><span class="p">(</span>
            <span class="n">permutation</span><span class="o">=</span><span class="n">permutation</span><span class="p">)</span>
        <span class="n">pperf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwocc</span><span class="p">()</span>
        <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">pdist</span><span class="p">,</span>
                                   <span class="n">points_perfect</span><span class="o">=</span><span class="n">pperf</span><span class="p">)</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wcs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">])</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wcs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;translation_vector_wcs_ctwocc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_without_centre</span>
        <span class="c1"># With central site, centered on the centroid (centroid includes the central site)</span>
        <span class="n">pdist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">(</span>
            <span class="n">permutation</span><span class="o">=</span><span class="n">permutation</span><span class="p">)</span>
        <span class="n">pperf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">()</span>
        <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">pdist</span><span class="p">,</span>
                                   <span class="n">points_perfect</span><span class="o">=</span><span class="n">pperf</span><span class="p">)</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;csm_wcs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wcs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">])</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wcs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;translation_vector_wcs_ctwcc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>
        <span class="c1"># With central site, centered on the central site</span>
        <span class="n">pdist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_csc</span><span class="p">(</span>
            <span class="n">permutation</span><span class="o">=</span><span class="n">permutation</span><span class="p">)</span>
        <span class="n">pperf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wcs_csc</span><span class="p">()</span>
        <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">pdist</span><span class="p">,</span>
                                   <span class="n">points_perfect</span><span class="o">=</span><span class="n">pperf</span><span class="p">)</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;csm_wcs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;rotation_matrix_wcs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">])</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;scaling_factor_wcs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">]</span>
        <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">][</span><span class="s1">&#39;translation_vector_wcs_csc&#39;</span><span class="p">]</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">bare_centre</span>

<div class="viewcode-block" id="LocalGeometryFinder.get_coordination_symmetry_measures_optim"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.get_coordination_symmetry_measures_optim">[docs]</a>    <span class="k">def</span> <span class="nf">get_coordination_symmetry_measures_optim</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">only_minimum</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                 <span class="n">all_csms</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nb_set</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the continuous symmetry measures of the current local geometry in a dictionary.</span>
<span class="sd">        :return: the continuous symmetry measures of the current local geometry in a dictionary.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cn</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="p">)</span>
        <span class="n">test_geometries</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">get_implemented_geometries</span><span class="p">(</span><span class="n">cn</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">all</span><span class="p">([</span><span class="n">cg</span><span class="o">.</span><span class="n">algorithms</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">algorithm_type</span> <span class="o">==</span> <span class="n">EXPLICIT_PERMUTATIONS</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">test_geometries</span><span class="p">]):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_coordination_symmetry_measures</span><span class="p">(</span><span class="n">only_minimum</span><span class="o">=</span><span class="n">only_minimum</span><span class="p">,</span> <span class="n">all_csms</span><span class="o">=</span><span class="n">all_csms</span><span class="p">,</span>
                                                           <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">([</span><span class="nb">all</span><span class="p">([</span><span class="n">algo</span><span class="o">.</span><span class="n">algorithm_type</span> <span class="o">==</span> <span class="n">SEPARATION_PLANE</span>
                         <span class="k">for</span> <span class="n">algo</span> <span class="ow">in</span> <span class="n">cg</span><span class="o">.</span><span class="n">algorithms</span><span class="p">])</span> <span class="k">for</span> <span class="n">cg</span> <span class="ow">in</span> <span class="n">test_geometries</span><span class="p">]):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;All algorithms should be EXPLICIT_PERMUTATIONS or SEPARATION_PLANE&#39;</span><span class="p">)</span>

        <span class="n">result_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">geometry</span> <span class="ow">in</span> <span class="n">test_geometries</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s1">&#39;Getting Continuous Symmetry Measure with Separation Plane &#39;</span>
                                     <span class="s1">&#39;algorithm for geometry &quot;</span><span class="si">{}</span><span class="s1">&quot;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">geometry</span><span class="o">.</span><span class="n">ce_symbol</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span> <span class="o">=</span> <span class="n">AbstractGeometry</span><span class="o">.</span><span class="n">from_cg</span><span class="p">(</span>
                <span class="n">cg</span><span class="o">=</span><span class="n">geometry</span><span class="p">,</span>
                <span class="n">centering_type</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centering_type</span><span class="p">,</span>
                <span class="n">include_central_site_in_centroid</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">include_central_site_in_centroid</span><span class="p">)</span>
            <span class="n">points_perfect</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">perfect_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">()</span>
            <span class="n">cgsm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_geometry_symmetry_measures_sepplane_optim</span><span class="p">(</span><span class="n">geometry</span><span class="p">,</span>
                                                                               <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">,</span>
                                                                               <span class="n">nb_set</span><span class="o">=</span><span class="n">nb_set</span><span class="p">,</span>
                                                                               <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
            <span class="n">result</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="n">cgsm</span>
            <span class="k">if</span> <span class="n">only_minimum</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">result</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">imin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">([</span><span class="n">rr</span><span class="p">[</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">rr</span> <span class="ow">in</span> <span class="n">result</span><span class="p">])</span>
                    <span class="k">if</span> <span class="n">geometry</span><span class="o">.</span><span class="n">algorithms</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="n">algo</span> <span class="o">=</span> <span class="n">algos</span><span class="p">[</span><span class="n">imin</span><span class="p">]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">algo</span> <span class="o">=</span> <span class="n">algos</span>
                    <span class="n">result_dict</span><span class="p">[</span><span class="n">geometry</span><span class="o">.</span><span class="n">mp_symbol</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;csm&#39;</span><span class="p">:</span> <span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;symmetry_measure&#39;</span><span class="p">],</span>
                                                       <span class="s1">&#39;indices&#39;</span><span class="p">:</span> <span class="n">permutations</span><span class="p">[</span>
                                                           <span class="n">imin</span><span class="p">],</span>
                                                       <span class="s1">&#39;algo&#39;</span><span class="p">:</span> <span class="n">algo</span><span class="p">,</span>
                                                       <span class="s1">&#39;local2perfect_map&#39;</span><span class="p">:</span>
                                                           <span class="n">local2perfect_maps</span><span class="p">[</span>
                                                               <span class="n">imin</span><span class="p">],</span>
                                                       <span class="s1">&#39;perfect2local_map&#39;</span><span class="p">:</span>
                                                           <span class="n">perfect2local_maps</span><span class="p">[</span>
                                                               <span class="n">imin</span><span class="p">],</span>
                                                       <span class="s1">&#39;scaling_factor&#39;</span><span class="p">:</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;scaling_factor&#39;</span><span class="p">],</span>
                                                       <span class="s1">&#39;rotation_matrix&#39;</span><span class="p">:</span>
                                                           <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;rotation_matrix&#39;</span><span class="p">]),</span>
                                                       <span class="s1">&#39;translation_vector&#39;</span><span class="p">:</span> <span class="n">result</span><span class="p">[</span><span class="n">imin</span><span class="p">][</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]}</span>
                    <span class="k">if</span> <span class="n">all_csms</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_update_results_all_csms</span><span class="p">(</span><span class="n">result_dict</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">imin</span><span class="p">,</span> <span class="n">geometry</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">result_dict</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.coordination_geometry_symmetry_measures"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.coordination_geometry_symmetry_measures">[docs]</a>    <span class="k">def</span> <span class="nf">coordination_geometry_symmetry_measures</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination_geometry</span><span class="p">,</span>
                                                <span class="n">tested_permutations</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                                <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the symmetry measures of a given coordination_geometry for a set of permutations depending on</span>
<span class="sd">        the permutation setup. Depending on the parameters of the LocalGeometryFinder and on the coordination</span>
<span class="sd">         geometry, different methods are called.</span>
<span class="sd">        :param coordination_geometry: Coordination geometry for which the symmetry measures are looked for</span>
<span class="sd">        :return: the symmetry measures of a given coordination_geometry for a set of permutations</span>
<span class="sd">        :raise: NotImplementedError if the permutation_setup does not exists</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">tested_permutations</span><span class="p">:</span>
            <span class="n">tested_permutations</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">permutations_safe_override</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;No permutations safe override anymore&#39;</span><span class="p">)</span>
        <span class="n">csms</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">permutations</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">algos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">local2perfect_maps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">algo</span> <span class="ow">in</span> <span class="n">coordination_geometry</span><span class="o">.</span><span class="n">algorithms</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">algo</span><span class="o">.</span><span class="n">algorithm_type</span> <span class="o">==</span> <span class="n">EXPLICIT_PERMUTATIONS</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_geometry_symmetry_measures_standard</span><span class="p">(</span>
                    <span class="n">coordination_geometry</span><span class="p">,</span> <span class="n">algo</span><span class="p">,</span>
                    <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">,</span>
                    <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">algo</span><span class="o">.</span><span class="n">algorithm_type</span> <span class="o">==</span> <span class="n">SEPARATION_PLANE</span><span class="p">:</span>
                <span class="n">cgsm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_geometry_symmetry_measures_separation_plane</span><span class="p">(</span>
                    <span class="n">coordination_geometry</span><span class="p">,</span>
                    <span class="n">algo</span><span class="p">,</span>
                    <span class="n">tested_permutations</span><span class="o">=</span><span class="n">tested_permutations</span><span class="p">,</span>
                    <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
                <span class="n">csm</span><span class="p">,</span> <span class="n">perm</span><span class="p">,</span> <span class="n">algo</span><span class="p">,</span> <span class="n">local2perfect_map</span><span class="p">,</span> <span class="n">perfect2local_map</span> <span class="o">=</span> <span class="n">cgsm</span>

                <span class="n">csms</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">csm</span><span class="p">)</span>
                <span class="n">permutations</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
                <span class="n">algos</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">algo</span><span class="p">)</span>
                <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">local2perfect_map</span><span class="p">)</span>
                <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">perfect2local_map</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">csms</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.coordination_geometry_symmetry_measures_sepplane_optim"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.coordination_geometry_symmetry_measures_sepplane_optim">[docs]</a>    <span class="k">def</span> <span class="nf">coordination_geometry_symmetry_measures_sepplane_optim</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination_geometry</span><span class="p">,</span>
                                                               <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                                               <span class="n">nb_set</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the symmetry measures of a given coordination_geometry for a set of permutations depending on</span>
<span class="sd">        the permutation setup. Depending on the parameters of the LocalGeometryFinder and on the coordination</span>
<span class="sd">         geometry, different methods are called.</span>
<span class="sd">        :param coordination_geometry: Coordination geometry for which the symmetry measures are looked for</span>
<span class="sd">        :return: the symmetry measures of a given coordination_geometry for a set of permutations</span>
<span class="sd">        :raise: NotImplementedError if the permutation_setup does not exists</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">csms</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">permutations</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">algos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">local2perfect_maps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">algo</span> <span class="ow">in</span> <span class="n">coordination_geometry</span><span class="o">.</span><span class="n">algorithms</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">algo</span><span class="o">.</span><span class="n">algorithm_type</span> <span class="o">==</span> <span class="n">SEPARATION_PLANE</span><span class="p">:</span>
                <span class="n">cgsm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_geometry_symmetry_measures_separation_plane_optim</span><span class="p">(</span>
                    <span class="n">coordination_geometry</span><span class="p">,</span>
                    <span class="n">algo</span><span class="p">,</span>
                    <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">,</span>
                    <span class="n">nb_set</span><span class="o">=</span><span class="n">nb_set</span><span class="p">,</span>
                    <span class="n">optimization</span><span class="o">=</span><span class="n">optimization</span><span class="p">)</span>
                <span class="n">csm</span><span class="p">,</span> <span class="n">perm</span><span class="p">,</span> <span class="n">algo</span><span class="p">,</span> <span class="n">local2perfect_map</span><span class="p">,</span> <span class="n">perfect2local_map</span> <span class="o">=</span> <span class="n">cgsm</span>

                <span class="n">csms</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">csm</span><span class="p">)</span>
                <span class="n">permutations</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
                <span class="n">algos</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">algo</span><span class="p">)</span>
                <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">local2perfect_map</span><span class="p">)</span>
                <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">perfect2local_map</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">csms</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.coordination_geometry_symmetry_measures_standard"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.coordination_geometry_symmetry_measures_standard">[docs]</a>    <span class="k">def</span> <span class="nf">coordination_geometry_symmetry_measures_standard</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                                                         <span class="n">coordination_geometry</span><span class="p">,</span>
                                                         <span class="n">algo</span><span class="p">,</span>
                                                         <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                                         <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the symmetry measures for a set of permutations (whose setup depends on the coordination geometry)</span>
<span class="sd">        for the coordination geometry &quot;coordination_geometry&quot;. Standard implementation looking for the symmetry</span>
<span class="sd">        measures of each permutation</span>

<span class="sd">        :param coordination_geometry: The coordination geometry to be investigated</span>
<span class="sd">        :return: The symmetry measures for the given coordination geometry for each permutation investigated</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># permutations_symmetry_measures = np.zeros(len(algo.permutations),</span>
        <span class="c1">#                                           np.float)</span>
        <span class="k">if</span> <span class="n">optimization</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">algo</span><span class="o">.</span><span class="n">permutations</span><span class="p">)</span>
            <span class="n">permutations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">algos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">local2perfect_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">iperm</span><span class="p">,</span> <span class="n">perm</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">algo</span><span class="o">.</span><span class="n">permutations</span><span class="p">):</span>

                <span class="n">local2perfect_map</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">perfect2local_map</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">permutations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">iperfect</span><span class="p">,</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">perm</span><span class="p">):</span>
                    <span class="n">perfect2local_map</span><span class="p">[</span><span class="n">iperfect</span><span class="p">]</span> <span class="o">=</span> <span class="n">ii</span>
                    <span class="n">local2perfect_map</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">iperfect</span>
                <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">local2perfect_map</span><span class="p">)</span>
                <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">perfect2local_map</span><span class="p">)</span>

                <span class="n">points_distorted</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">(</span>
                    <span class="n">permutation</span><span class="o">=</span><span class="n">perm</span><span class="p">)</span>

                <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                                           <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
                <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>

                <span class="n">permutations_symmetry_measures</span><span class="p">[</span><span class="n">iperm</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span>
                <span class="n">algos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">algo</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">algo</span><span class="o">.</span><span class="n">permutations</span><span class="p">)</span>
            <span class="n">permutations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">algos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">local2perfect_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">iperm</span><span class="p">,</span> <span class="n">perm</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">algo</span><span class="o">.</span><span class="n">permutations</span><span class="p">):</span>

                <span class="n">local2perfect_map</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">perfect2local_map</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">permutations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">iperfect</span><span class="p">,</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">perm</span><span class="p">):</span>
                    <span class="n">perfect2local_map</span><span class="p">[</span><span class="n">iperfect</span><span class="p">]</span> <span class="o">=</span> <span class="n">ii</span>
                    <span class="n">local2perfect_map</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="o">=</span> <span class="n">iperfect</span>
                <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">local2perfect_map</span><span class="p">)</span>
                <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">perfect2local_map</span><span class="p">)</span>

                <span class="n">points_distorted</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">(</span>
                    <span class="n">permutation</span><span class="o">=</span><span class="n">perm</span><span class="p">)</span>

                <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                                           <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
                <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>

                <span class="n">permutations_symmetry_measures</span><span class="p">[</span><span class="n">iperm</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span>
                <span class="n">algos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">algo</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.coordination_geometry_symmetry_measures_separation_plane"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.coordination_geometry_symmetry_measures_separation_plane">[docs]</a>    <span class="k">def</span> <span class="nf">coordination_geometry_symmetry_measures_separation_plane</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                                                                 <span class="n">coordination_geometry</span><span class="p">,</span>
                                                                 <span class="n">separation_plane_algo</span><span class="p">,</span>
                                                                 <span class="n">testing</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                 <span class="n">tested_permutations</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                 <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the symmetry measures of the given coordination geometry &quot;coordination_geometry&quot; using separation</span>
<span class="sd">        facets to reduce the complexity of the system. Caller to the refined 2POINTS, 3POINTS and other ...</span>
<span class="sd">        :param coordination_geometry: The coordination geometry to be investigated</span>
<span class="sd">        :return: The symmetry measures for the given coordination geometry for each plane and permutation investigated</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">permutations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">plane_separations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">algos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">local2perfect_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
            <span class="n">separation_permutations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">nplanes</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">npoints</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">separation_plane_algo</span><span class="o">.</span><span class="n">minimum_number_of_points</span><span class="p">,</span>
                             <span class="nb">min</span><span class="p">(</span><span class="n">separation_plane_algo</span><span class="o">.</span><span class="n">maximum_number_of_points</span><span class="p">,</span>
                                 <span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">points_combination</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">combinations</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="n">npoints</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">npoints</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">collinear</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                 <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">central_site</span><span class="p">,</span>
                                 <span class="n">tolerance</span><span class="o">=</span><span class="mf">0.25</span><span class="p">):</span>
                        <span class="k">continue</span>
                    <span class="n">plane</span> <span class="o">=</span> <span class="n">Plane</span><span class="o">.</span><span class="n">from_3points</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                               <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                               <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">central_site</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">npoints</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">collinear</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                 <span class="n">points_combination</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">tolerance</span><span class="o">=</span><span class="mf">0.25</span><span class="p">):</span>
                        <span class="k">continue</span>
                    <span class="n">plane</span> <span class="o">=</span> <span class="n">Plane</span><span class="o">.</span><span class="n">from_3points</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                               <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                               <span class="n">points_combination</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="k">elif</span> <span class="n">npoints</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">plane</span> <span class="o">=</span> <span class="n">Plane</span><span class="o">.</span><span class="n">from_npoints</span><span class="p">(</span><span class="n">points_combination</span><span class="p">,</span>
                                               <span class="n">best_fit</span><span class="o">=</span><span class="s1">&#39;least_square_distance&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s1">&#39;Wrong number of points to initialize separation plane&#39;</span><span class="p">)</span>
                <span class="n">cgsm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cg_csm_separation_plane</span><span class="p">(</span>
                    <span class="n">coordination_geometry</span><span class="o">=</span><span class="n">coordination_geometry</span><span class="p">,</span>
                    <span class="n">sepplane</span><span class="o">=</span><span class="n">separation_plane_algo</span><span class="p">,</span>
                    <span class="n">local_plane</span><span class="o">=</span><span class="n">plane</span><span class="p">,</span>
                    <span class="n">plane_separations</span><span class="o">=</span><span class="n">plane_separations</span><span class="p">,</span>
                    <span class="n">dist_tolerances</span><span class="o">=</span><span class="n">DIST_TOLERANCES</span><span class="p">,</span>
                    <span class="n">testing</span><span class="o">=</span><span class="n">testing</span><span class="p">,</span>
                    <span class="n">tested_permutations</span><span class="o">=</span><span class="n">tested_permutations</span><span class="p">,</span>
                    <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
                <span class="n">csm</span><span class="p">,</span> <span class="n">perm</span><span class="p">,</span> <span class="n">algo</span> <span class="o">=</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>

                <span class="k">if</span> <span class="n">csm</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">permutations_symmetry_measures</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">csm</span><span class="p">)</span>
                    <span class="n">permutations</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
                    <span class="k">for</span> <span class="n">thisperm</span> <span class="ow">in</span> <span class="n">perm</span><span class="p">:</span>
                        <span class="n">p2l</span> <span class="o">=</span> <span class="p">{}</span>
                        <span class="n">l2p</span> <span class="o">=</span> <span class="p">{}</span>
                        <span class="k">for</span> <span class="n">i_p</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">thisperm</span><span class="p">):</span>
                            <span class="n">p2l</span><span class="p">[</span><span class="n">i_p</span><span class="p">]</span> <span class="o">=</span> <span class="n">pp</span>
                            <span class="n">l2p</span><span class="p">[</span><span class="n">pp</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_p</span>
                        <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p2l</span><span class="p">)</span>
                        <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l2p</span><span class="p">)</span>
                    <span class="n">algos</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">algo</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
                        <span class="n">separation_permutations</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">cgsm</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                    <span class="n">nplanes</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">nplanes</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">break</span>
        <span class="k">if</span> <span class="n">nplanes</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_geometry_symmetry_measures_fallback_random</span><span class="p">(</span>
                <span class="n">coordination_geometry</span><span class="p">,</span>
                <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">separation_permutations</span>
        <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span></div>

<div class="viewcode-block" id="LocalGeometryFinder.coordination_geometry_symmetry_measures_separation_plane_optim"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.coordination_geometry_symmetry_measures_separation_plane_optim">[docs]</a>    <span class="k">def</span> <span class="nf">coordination_geometry_symmetry_measures_separation_plane_optim</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                                                                       <span class="n">coordination_geometry</span><span class="p">,</span>
                                                                       <span class="n">separation_plane_algo</span><span class="p">,</span>
                                                                       <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                                                       <span class="n">nb_set</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                                                       <span class="n">optimization</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the symmetry measures of the given coordination geometry &quot;coordination_geometry&quot; using separation</span>
<span class="sd">        facets to reduce the complexity of the system. Caller to the refined 2POINTS, 3POINTS and other ...</span>
<span class="sd">        Args:</span>
<span class="sd">            coordination_geometry: The coordination geometry to be investigated.</span>
<span class="sd">            separation_plane_algo: Separation Plane algorithm used.</span>
<span class="sd">            points_perfect: Points corresponding to the perfect geometry.</span>
<span class="sd">            nb_set: Neighbor set for this set of points. (used to store already computed separation planes)</span>
<span class="sd">            optimization: Optimization level (1 or 2).</span>

<span class="sd">        Returns:</span>
<span class="sd">            tuple: Continuous symmetry measures for the given coordination geometry for each plane and permutation</span>
<span class="sd">                   investigated, corresponding permutations, corresponding algorithms,</span>
<span class="sd">                   corresponding mappings from local to perfect environment and corresponding mappings</span>
<span class="sd">                   from perfect to local environment.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">optimization</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s1">&#39;... using optimization = 2&#39;</span><span class="p">)</span>
            <span class="n">cgcsmoptim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cg_csm_separation_plane_optim2</span>
        <span class="k">elif</span> <span class="n">optimization</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s1">&#39;... using optimization = 2&#39;</span><span class="p">)</span>
            <span class="n">cgcsmoptim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cg_csm_separation_plane_optim1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Optimization should be 1 or 2&#39;</span><span class="p">)</span>
        <span class="n">cn</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="p">)</span>

        <span class="n">permutations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">algos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">local2perfect_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">separation_plane_algo</span><span class="o">.</span><span class="n">separation</span> <span class="ow">in</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">separations</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">sep_indices</span><span class="p">,</span> <span class="p">(</span><span class="n">local_plane</span><span class="p">,</span> <span class="n">npsep</span><span class="p">)</span> <span class="ow">in</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">separations</span><span class="p">[</span><span class="n">separation_plane_algo</span><span class="o">.</span><span class="n">separation</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">cgsm</span> <span class="o">=</span> <span class="n">cgcsmoptim</span><span class="p">(</span><span class="n">coordination_geometry</span><span class="o">=</span><span class="n">coordination_geometry</span><span class="p">,</span>
                                  <span class="n">sepplane</span><span class="o">=</span><span class="n">separation_plane_algo</span><span class="p">,</span>
                                  <span class="n">local_plane</span><span class="o">=</span><span class="n">local_plane</span><span class="p">,</span>
                                  <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">,</span>
                                  <span class="n">separation_indices</span><span class="o">=</span><span class="n">npsep</span><span class="p">)</span>
                <span class="n">csm</span><span class="p">,</span> <span class="n">perm</span><span class="p">,</span> <span class="n">algo</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
                <span class="n">permutations_symmetry_measures</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">csm</span><span class="p">)</span>
                <span class="n">permutations</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">thisperm</span> <span class="ow">in</span> <span class="n">perm</span><span class="p">:</span>
                    <span class="n">p2l</span> <span class="o">=</span> <span class="p">{}</span>
                    <span class="n">l2p</span> <span class="o">=</span> <span class="p">{}</span>
                    <span class="k">for</span> <span class="n">i_p</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">thisperm</span><span class="p">):</span>
                        <span class="n">p2l</span><span class="p">[</span><span class="n">i_p</span><span class="p">]</span> <span class="o">=</span> <span class="n">pp</span>
                        <span class="n">l2p</span><span class="p">[</span><span class="n">pp</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_p</span>
                    <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p2l</span><span class="p">)</span>
                    <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l2p</span><span class="p">)</span>
                <span class="n">algos</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">algo</span><span class="p">)</span>

        <span class="c1"># Get the local planes and separations up to 3 points</span>
        <span class="k">for</span> <span class="n">npoints</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">minpoints</span><span class="p">[</span><span class="n">cn</span><span class="p">],</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">maxpoints</span><span class="p">[</span><span class="n">cn</span><span class="p">],</span> <span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">ipoints_combination</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">combinations</span><span class="p">(</span>
                    <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">cn</span><span class="p">),</span> <span class="n">npoints</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">ipoints_combination</span> <span class="ow">in</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">local_planes</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="c1"># Set up new plane</span>
                <span class="n">nb_set</span><span class="o">.</span><span class="n">local_planes</span><span class="p">[</span><span class="n">ipoints_combination</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="n">points_combination</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="p">[</span><span class="n">ip</span><span class="p">]</span> <span class="k">for</span> <span class="n">ip</span> <span class="ow">in</span> <span class="n">ipoints_combination</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">npoints</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">collinear</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                 <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">central_site</span><span class="p">,</span>
                                 <span class="n">tolerance</span><span class="o">=</span><span class="mf">0.25</span><span class="p">):</span>
                        <span class="k">continue</span>
                    <span class="n">plane</span> <span class="o">=</span> <span class="n">Plane</span><span class="o">.</span><span class="n">from_3points</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                               <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                               <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">central_site</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">npoints</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">collinear</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                 <span class="n">points_combination</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">tolerance</span><span class="o">=</span><span class="mf">0.25</span><span class="p">):</span>
                        <span class="k">continue</span>
                    <span class="n">plane</span> <span class="o">=</span> <span class="n">Plane</span><span class="o">.</span><span class="n">from_3points</span><span class="p">(</span><span class="n">points_combination</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                               <span class="n">points_combination</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                               <span class="n">points_combination</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="k">elif</span> <span class="n">npoints</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">plane</span> <span class="o">=</span> <span class="n">Plane</span><span class="o">.</span><span class="n">from_npoints</span><span class="p">(</span><span class="n">points_combination</span><span class="p">,</span>
                                               <span class="n">best_fit</span><span class="o">=</span><span class="s1">&#39;least_square_distance&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s1">&#39;Wrong number of points to initialize separation plane&#39;</span><span class="p">)</span>
                <span class="c1"># Takes a lot of time and happens rarely ...</span>
                <span class="c1"># if any([plane.is_same_plane_as(plane2) for comb2, plane2 in nb_set.local_planes.items()</span>
                <span class="c1">#         if plane2 is not None]):</span>
                <span class="c1">#     continue</span>
                <span class="n">nb_set</span><span class="o">.</span><span class="n">local_planes</span><span class="p">[</span><span class="n">ipoints_combination</span><span class="p">]</span> <span class="o">=</span> <span class="n">plane</span>
                <span class="c1"># Get the separations for this plane</span>
                <span class="c1"># TODO: check sensitivity to delta/delta_factor parameter</span>
                <span class="n">dig</span> <span class="o">=</span> <span class="n">plane</span><span class="o">.</span><span class="n">distances_indices_groups</span><span class="p">(</span><span class="n">points</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">,</span> <span class="n">delta_factor</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span>
                                                     <span class="n">sign</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                <span class="n">grouped_indices</span> <span class="o">=</span> <span class="n">dig</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                <span class="n">new_seps</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">ng</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">grouped_indices</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
                    <span class="n">inplane</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="p">(</span><span class="o">*</span><span class="n">grouped_indices</span><span class="p">[:</span><span class="n">ng</span><span class="p">]))</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">inplane</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">maxpoints_inplane</span><span class="p">[</span><span class="n">cn</span><span class="p">]:</span>
                        <span class="k">break</span>
                    <span class="n">inplane</span> <span class="o">=</span> <span class="p">[</span><span class="n">ii</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">inplane</span><span class="p">]</span>
                    <span class="n">outplane</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="p">(</span><span class="o">*</span><span class="n">grouped_indices</span><span class="p">[</span><span class="n">ng</span><span class="p">:]))</span>
                    <span class="n">s1</span> <span class="o">=</span> <span class="p">[</span><span class="n">ii_sign</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii_sign</span> <span class="ow">in</span> <span class="n">outplane</span> <span class="k">if</span> <span class="n">ii_sign</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">]</span>
                    <span class="n">s2</span> <span class="o">=</span> <span class="p">[</span><span class="n">ii_sign</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii_sign</span> <span class="ow">in</span> <span class="n">outplane</span> <span class="k">if</span> <span class="n">ii_sign</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">]</span>
                    <span class="n">separation</span> <span class="o">=</span> <span class="n">sort_separation_tuple</span><span class="p">([</span><span class="n">s1</span><span class="p">,</span> <span class="n">inplane</span><span class="p">,</span> <span class="n">s2</span><span class="p">])</span>
                    <span class="n">sep</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="n">gg</span><span class="p">)</span> <span class="k">for</span> <span class="n">gg</span> <span class="ow">in</span> <span class="n">separation</span><span class="p">])</span>
                    <span class="k">if</span> <span class="n">sep</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">allcg</span><span class="o">.</span><span class="n">separations_cg</span><span class="p">[</span><span class="n">cn</span><span class="p">]:</span>
                        <span class="k">continue</span>
                    <span class="k">if</span> <span class="n">sep</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">nb_set</span><span class="o">.</span><span class="n">separations</span><span class="p">:</span>
                        <span class="n">nb_set</span><span class="o">.</span><span class="n">separations</span><span class="p">[</span><span class="n">sep</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                    <span class="n">mysep</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ss</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int8</span><span class="p">)</span> <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="n">separation</span><span class="p">]</span>
                    <span class="n">nb_set</span><span class="o">.</span><span class="n">separations</span><span class="p">[</span><span class="n">sep</span><span class="p">][</span><span class="n">separation</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">plane</span><span class="p">,</span> <span class="n">mysep</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">sep</span> <span class="o">==</span> <span class="n">separation_plane_algo</span><span class="o">.</span><span class="n">separation</span><span class="p">:</span>
                        <span class="n">new_seps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mysep</span><span class="p">)</span>

                <span class="k">for</span> <span class="n">separation_indices</span> <span class="ow">in</span> <span class="n">new_seps</span><span class="p">:</span>
                    <span class="n">cgsm</span> <span class="o">=</span> <span class="n">cgcsmoptim</span><span class="p">(</span><span class="n">coordination_geometry</span><span class="o">=</span><span class="n">coordination_geometry</span><span class="p">,</span>
                                      <span class="n">sepplane</span><span class="o">=</span><span class="n">separation_plane_algo</span><span class="p">,</span>
                                      <span class="n">local_plane</span><span class="o">=</span><span class="n">plane</span><span class="p">,</span>
                                      <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">,</span>
                                      <span class="n">separation_indices</span><span class="o">=</span><span class="n">separation_indices</span><span class="p">)</span>
                    <span class="n">csm</span><span class="p">,</span> <span class="n">perm</span><span class="p">,</span> <span class="n">algo</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">cgsm</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
                    <span class="n">permutations_symmetry_measures</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">csm</span><span class="p">)</span>
                    <span class="n">permutations</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
                    <span class="k">for</span> <span class="n">thisperm</span> <span class="ow">in</span> <span class="n">perm</span><span class="p">:</span>
                        <span class="n">p2l</span> <span class="o">=</span> <span class="p">{}</span>
                        <span class="n">l2p</span> <span class="o">=</span> <span class="p">{}</span>
                        <span class="k">for</span> <span class="n">i_p</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">thisperm</span><span class="p">):</span>
                            <span class="n">p2l</span><span class="p">[</span><span class="n">i_p</span><span class="p">]</span> <span class="o">=</span> <span class="n">pp</span>
                            <span class="n">l2p</span><span class="p">[</span><span class="n">pp</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_p</span>
                        <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p2l</span><span class="p">)</span>
                        <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l2p</span><span class="p">)</span>
                    <span class="n">algos</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">algo</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">permutations_symmetry_measures</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">coordination_geometry_symmetry_measures_fallback_random</span><span class="p">(</span>
                <span class="n">coordination_geometry</span><span class="p">,</span>
                <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span></div>

    <span class="k">def</span> <span class="nf">_cg_csm_separation_plane</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination_geometry</span><span class="p">,</span> <span class="n">sepplane</span><span class="p">,</span>
                                 <span class="n">local_plane</span><span class="p">,</span>
                                 <span class="n">plane_separations</span><span class="p">,</span>
                                 <span class="n">dist_tolerances</span><span class="o">=</span><span class="n">DIST_TOLERANCES</span><span class="p">,</span>
                                 <span class="n">testing</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">tested_permutations</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                 <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">argref_separation</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">argsorted_ref_separation_perm</span>
        <span class="n">plane_found</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">dist_tolerance</span> <span class="ow">in</span> <span class="n">dist_tolerances</span><span class="p">:</span>
            <span class="n">permutations</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
                <span class="n">separation_permutations</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">algo</span> <span class="o">=</span> <span class="s1">&#39;NOT_FOUND&#39;</span>
            <span class="n">separation</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">indices_separate</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">,</span> <span class="n">dist_tolerance</span><span class="p">)</span>
            <span class="c1"># Do not consider facets leading to the same separation indices</span>
            <span class="n">separation</span> <span class="o">=</span> <span class="n">sort_separation</span><span class="p">(</span><span class="n">separation</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">separation_in_list</span><span class="p">(</span><span class="n">separation</span><span class="p">,</span> <span class="n">plane_separations</span><span class="p">):</span>
                <span class="k">continue</span>
            <span class="c1"># Do not consider a separation which does not follow the reference separation of the perfect</span>
            <span class="c1"># coordination geometry</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">separation</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">sepplane</span><span class="o">.</span><span class="n">plane_points</span><span class="p">):</span>
                <span class="k">continue</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">separation</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">sepplane</span><span class="o">.</span><span class="n">point_groups</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
                <span class="n">this_separation</span> <span class="o">=</span> <span class="n">separation</span>
                <span class="n">plane_separations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">this_separation</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">separation</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">sepplane</span><span class="o">.</span><span class="n">point_groups</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
                <span class="n">this_separation</span> <span class="o">=</span> <span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="n">separation</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="nb">list</span><span class="p">(</span><span class="n">separation</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                   <span class="nb">list</span><span class="p">(</span><span class="n">separation</span><span class="p">[</span><span class="mi">0</span><span class="p">])]</span>
                <span class="n">plane_separations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">this_separation</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_plane</span><span class="p">:</span>
                <span class="n">inp</span> <span class="o">=</span> <span class="p">[</span><span class="n">pp</span> <span class="k">for</span> <span class="n">ip</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">)</span>
                       <span class="k">if</span> <span class="n">ip</span> <span class="ow">in</span> <span class="n">this_separation</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span>

                <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
                    <span class="n">pp_s0</span> <span class="o">=</span> <span class="p">[</span><span class="n">pp</span> <span class="k">for</span> <span class="n">ip</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span>
                             <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">)</span> <span class="k">if</span>
                             <span class="n">ip</span> <span class="ow">in</span> <span class="n">this_separation</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
                    <span class="n">ordind_s0</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span>
                        <span class="n">pp_s0</span><span class="p">)</span>
                    <span class="n">sep0</span> <span class="o">=</span> <span class="p">[</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">ordind_s0</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">sep0</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                    <span class="n">pp_s2</span> <span class="o">=</span> <span class="p">[</span><span class="n">pp</span> <span class="k">for</span> <span class="n">ip</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span>
                             <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">)</span> <span class="k">if</span>
                             <span class="n">ip</span> <span class="ow">in</span> <span class="n">this_separation</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
                    <span class="n">ordind_s2</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span>
                        <span class="n">pp_s2</span><span class="p">)</span>
                    <span class="n">sep2</span> <span class="o">=</span> <span class="p">[</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">ordind_s2</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">sep2</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">separation_perm</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">sep0</span><span class="p">)</span>
                <span class="n">ordind</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span><span class="n">inp</span><span class="p">)</span>
                <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
                    <span class="p">[</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">ordind</span><span class="p">])</span>
                <span class="n">algo</span> <span class="o">=</span> <span class="s1">&#39;SEPARATION_PLANE_2POINTS_ORDERED&#39;</span>
                <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">sep2</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">separation_perm</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">algo</span> <span class="o">=</span> <span class="s1">&#39;SEPARATION_PLANE_2POINTS&#39;</span>
                <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">this_separation</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plane_safe_permutations</span><span class="p">:</span>
                <span class="n">sep_perms</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">safe_separation_permutations</span><span class="p">(</span>
                    <span class="n">ordered_plane</span><span class="o">=</span><span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_plane</span><span class="p">,</span>
                    <span class="n">ordered_point_groups</span><span class="o">=</span><span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">sep_perms</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">permutations</span>

            <span class="c1"># plane_found = True</span>

            <span class="k">for</span> <span class="n">i_sep_perm</span><span class="p">,</span> <span class="n">sep_perm</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sep_perms</span><span class="p">):</span>
                <span class="n">perm1</span> <span class="o">=</span> <span class="p">[</span><span class="n">separation_perm</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">sep_perm</span><span class="p">]</span>
                <span class="n">pp</span> <span class="o">=</span> <span class="p">[</span><span class="n">perm1</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">argref_separation</span><span class="p">]</span>
                <span class="c1"># Skip permutations that have already been performed</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tested_permutations</span><span class="p">,</span> <span class="nb">set</span><span class="p">)</span> <span class="ow">and</span> <span class="n">coordination_geometry</span><span class="o">.</span><span class="n">equivalent_indices</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">tuple_ref_perm</span> <span class="o">=</span> <span class="n">coordination_geometry</span><span class="o">.</span><span class="n">ref_permutation</span><span class="p">(</span><span class="n">pp</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">tuple_ref_perm</span> <span class="ow">in</span> <span class="n">tested_permutations</span><span class="p">:</span>
                        <span class="k">continue</span>
                    <span class="n">tested_permutations</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">tuple_ref_perm</span><span class="p">)</span>

                <span class="n">permutations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
                    <span class="n">separation_permutations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sep_perm</span><span class="p">)</span>

                <span class="n">points_distorted</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">(</span>
                    <span class="n">permutation</span><span class="o">=</span><span class="n">pp</span><span class="p">)</span>

                <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                                           <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
                <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>

                <span class="n">permutations_symmetry_measures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sm_info</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">plane_found</span><span class="p">:</span>
                <span class="k">break</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">permutations_symmetry_measures</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algo</span><span class="p">,</span> <span class="n">separation_permutations</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="p">[</span>
                    <span class="n">sepplane</span><span class="o">.</span><span class="n">algorithm_type</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">permutations</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">plane_found</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
                    <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="p">[],</span> <span class="p">[]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="p">[]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">testing</span><span class="p">:</span>
                    <span class="k">return</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>

    <span class="k">def</span> <span class="nf">_cg_csm_separation_plane_optim1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination_geometry</span><span class="p">,</span>
                                        <span class="n">sepplane</span><span class="p">,</span>
                                        <span class="n">local_plane</span><span class="p">,</span>
                                        <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                        <span class="n">separation_indices</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">argref_separation</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">argsorted_ref_separation_perm</span>
        <span class="n">permutations</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">stop_search</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="c1"># TODO: do not do that several times ... also keep in memory</span>
        <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_plane</span><span class="p">:</span>
            <span class="n">inp</span> <span class="o">=</span> <span class="p">[</span><span class="n">pp</span> <span class="k">for</span> <span class="n">ip</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">)</span>
                   <span class="k">if</span> <span class="n">ip</span> <span class="ow">in</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span>
            <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
                <span class="n">pp_s0</span> <span class="o">=</span> <span class="p">[</span><span class="n">pp</span> <span class="k">for</span> <span class="n">ip</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span>
                         <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">)</span> <span class="k">if</span>
                         <span class="n">ip</span> <span class="ow">in</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
                <span class="n">ordind_s0</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span>
                    <span class="n">pp_s0</span><span class="p">)</span>
                <span class="n">sep0</span> <span class="o">=</span> <span class="p">[</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">ordind_s0</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">sep0</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                <span class="n">pp_s2</span> <span class="o">=</span> <span class="p">[</span><span class="n">pp</span> <span class="k">for</span> <span class="n">ip</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span>
                         <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">_coords</span><span class="p">)</span> <span class="k">if</span>
                         <span class="n">ip</span> <span class="ow">in</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
                <span class="n">ordind_s2</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span>
                    <span class="n">pp_s2</span><span class="p">)</span>
                <span class="n">sep2</span> <span class="o">=</span> <span class="p">[</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">ordind_s2</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">sep2</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
            <span class="n">separation_perm</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">sep0</span><span class="p">)</span>
            <span class="n">ordind</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span><span class="n">inp</span><span class="p">)</span>
            <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
                <span class="p">[</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">ordind</span><span class="p">])</span>
            <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">sep2</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">separation_perm</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">separation_perm</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plane_safe_permutations</span><span class="p">:</span>
            <span class="n">sep_perms</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">safe_separation_permutations</span><span class="p">(</span>
                <span class="n">ordered_plane</span><span class="o">=</span><span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_plane</span><span class="p">,</span>
                <span class="n">ordered_point_groups</span><span class="o">=</span><span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sep_perms</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">permutations</span>

        <span class="k">for</span> <span class="n">i_sep_perm</span><span class="p">,</span> <span class="n">sep_perm</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sep_perms</span><span class="p">):</span>
            <span class="n">perm1</span> <span class="o">=</span> <span class="p">[</span><span class="n">separation_perm</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">sep_perm</span><span class="p">]</span>
            <span class="n">pp</span> <span class="o">=</span> <span class="p">[</span><span class="n">perm1</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span> <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="n">argref_separation</span><span class="p">]</span>

            <span class="n">permutations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp</span><span class="p">)</span>

            <span class="n">points_distorted</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">(</span>
                <span class="n">permutation</span><span class="o">=</span><span class="n">pp</span><span class="p">)</span>

            <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                                       <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>

            <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>

            <span class="n">permutations_symmetry_measures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sm_info</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">permutations_symmetry_measures</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="p">[</span><span class="n">sepplane</span><span class="o">.</span><span class="n">algorithm_type</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span>
                <span class="n">permutations</span><span class="p">),</span> <span class="n">stop_search</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="n">stop_search</span>

    <span class="k">def</span> <span class="nf">_cg_csm_separation_plane_optim2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordination_geometry</span><span class="p">,</span>
                                        <span class="n">sepplane</span><span class="p">,</span>
                                        <span class="n">local_plane</span><span class="p">,</span>
                                        <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                        <span class="n">separation_indices</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">argref_separation</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">argsorted_ref_separation_perm</span>
        <span class="n">permutations</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">stop_search</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="c1"># TODO: do not do that several times ... also keep in memory</span>
        <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_plane</span><span class="p">:</span>
            <span class="n">inp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
                <span class="n">pp_s0</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                <span class="n">ordind_s0</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span>
                    <span class="n">pp_s0</span><span class="p">)</span>
                <span class="c1"># sep0 = [separation_indices[0][ii] for ii in ordind_s0]</span>
                <span class="n">sep0</span> <span class="o">=</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">ordind_s0</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># sep0 = list(separation_indices[0])</span>
                <span class="n">sep0</span> <span class="o">=</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                <span class="n">pp_s2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">coords</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                <span class="n">ordind_s2</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span>
                    <span class="n">pp_s2</span><span class="p">)</span>
                <span class="c1"># sep2 = [separation_indices[2][ii] for ii in ordind_s2]</span>
                <span class="n">sep2</span> <span class="o">=</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">ordind_s2</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># sep2 = list(separation_indices[2])</span>
                <span class="n">sep2</span> <span class="o">=</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            <span class="c1"># separation_perm = list(sep0)</span>
            <span class="n">ordind</span> <span class="o">=</span> <span class="n">local_plane</span><span class="o">.</span><span class="n">project_and_to2dim_ordered_indices</span><span class="p">(</span><span class="n">inp</span><span class="p">)</span>
            <span class="c1"># separation_perm.extend(</span>
            <span class="c1">#     [separation_indices[1][ii] for ii in ordind])</span>
            <span class="n">inp1</span> <span class="o">=</span> <span class="n">separation_indices</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">ordind</span><span class="p">)</span>
            <span class="c1"># separation_perm.extend(sep2)</span>
            <span class="n">separation_perm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="n">sep0</span><span class="p">,</span> <span class="n">inp1</span><span class="p">,</span> <span class="n">sep2</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># separation_perm = list(separation_indices[0])</span>
            <span class="c1"># separation_perm.extend(separation_indices[1])</span>
            <span class="c1"># separation_perm.extend(separation_indices[2])</span>
            <span class="n">separation_perm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">separation_indices</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plane_safe_permutations</span><span class="p">:</span>
            <span class="n">sep_perms</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">safe_separation_permutations</span><span class="p">(</span>
                <span class="n">ordered_plane</span><span class="o">=</span><span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_plane</span><span class="p">,</span>
                <span class="n">ordered_point_groups</span><span class="o">=</span><span class="n">sepplane</span><span class="o">.</span><span class="n">ordered_point_groups</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sep_perms</span> <span class="o">=</span> <span class="n">sepplane</span><span class="o">.</span><span class="n">permutations</span>

        <span class="k">for</span> <span class="n">i_sep_perm</span><span class="p">,</span> <span class="n">sep_perm</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sep_perms</span><span class="p">):</span>
            <span class="n">perm1</span> <span class="o">=</span> <span class="n">separation_perm</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">sep_perm</span><span class="p">)</span>
            <span class="n">pp</span> <span class="o">=</span> <span class="n">perm1</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="n">argref_separation</span><span class="p">)</span>

            <span class="n">permutations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp</span><span class="p">)</span>

            <span class="n">points_distorted</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">(</span>
                <span class="n">permutation</span><span class="o">=</span><span class="n">pp</span><span class="p">)</span>

            <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                                       <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>

            <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>

            <span class="n">permutations_symmetry_measures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sm_info</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">permutations_symmetry_measures</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="p">[</span><span class="n">sepplane</span><span class="o">.</span><span class="n">algorithm_type</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span>
                <span class="n">permutations</span><span class="p">),</span> <span class="n">stop_search</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="n">stop_search</span>

<div class="viewcode-block" id="LocalGeometryFinder.coordination_geometry_symmetry_measures_fallback_random"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.html#pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder.LocalGeometryFinder.coordination_geometry_symmetry_measures_fallback_random">[docs]</a>    <span class="k">def</span> <span class="nf">coordination_geometry_symmetry_measures_fallback_random</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                                                                <span class="n">coordination_geometry</span><span class="p">,</span>
                                                                <span class="n">NRANDOM</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
                                                                <span class="n">points_perfect</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the symmetry measures for a random set of permutations for the coordination geometry</span>
<span class="sd">        &quot;coordination_geometry&quot;. Fallback implementation for the plane separation algorithms measures</span>
<span class="sd">        of each permutation</span>

<span class="sd">        :param coordination_geometry: The coordination geometry to be investigated</span>
<span class="sd">        :param NRANDOM: Number of random permutations to be tested</span>
<span class="sd">        :return: The symmetry measures for the given coordination geometry for each permutation investigated</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">permutations_symmetry_measures</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="n">NRANDOM</span>
        <span class="n">permutations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">algos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">perfect2local_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">local2perfect_maps</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">iperm</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">NRANDOM</span><span class="p">):</span>
            <span class="n">perm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">permutation</span><span class="p">(</span>
                <span class="n">coordination_geometry</span><span class="o">.</span><span class="n">coordination_number</span><span class="p">)</span>
            <span class="n">permutations</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
            <span class="n">p2l</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="n">l2p</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">i_p</span><span class="p">,</span> <span class="n">pp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">perm</span><span class="p">):</span>
                <span class="n">p2l</span><span class="p">[</span><span class="n">i_p</span><span class="p">]</span> <span class="o">=</span> <span class="n">pp</span>
                <span class="n">l2p</span><span class="p">[</span><span class="n">pp</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_p</span>
            <span class="n">perfect2local_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p2l</span><span class="p">)</span>
            <span class="n">local2perfect_maps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l2p</span><span class="p">)</span>

            <span class="n">points_distorted</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">points_wcs_ctwcc</span><span class="p">(</span>
                <span class="n">permutation</span><span class="o">=</span><span class="n">perm</span><span class="p">)</span>
            <span class="n">sm_info</span> <span class="o">=</span> <span class="n">symmetry_measure</span><span class="p">(</span><span class="n">points_distorted</span><span class="o">=</span><span class="n">points_distorted</span><span class="p">,</span>
                                       <span class="n">points_perfect</span><span class="o">=</span><span class="n">points_perfect</span><span class="p">)</span>
            <span class="n">sm_info</span><span class="p">[</span><span class="s1">&#39;translation_vector&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">local_geometry</span><span class="o">.</span><span class="n">centroid_with_centre</span>

            <span class="n">permutations_symmetry_measures</span><span class="p">[</span><span class="n">iperm</span><span class="p">]</span> <span class="o">=</span> <span class="n">sm_info</span>
            <span class="n">algos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;APPROXIMATE_FALLBACK&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">permutations_symmetry_measures</span><span class="p">,</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">algos</span><span class="p">,</span> <span class="n">local2perfect_maps</span><span class="p">,</span> <span class="n">perfect2local_maps</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>